Skip to content

Open the image and diagram zoom views in native dialogs - #4966

Merged
reakaleek merged 10 commits into
mainfrom
modals-native-dialog
Nov 19, 2026
Merged

reakaleek merged 10 commits into
mainfrom
modals-native-dialog

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

The Mermaid fullscreen view and the legacy image modal are now native <dialog> elements opened with showModal(), so Escape, focus return and the backdrop work the way every other modal on the site already does.

Affects: Authoring, Site UI

Prompt summary: Every floating or modal element in the docs UI should use one standard primitive. Most modals already use <dialog>; this PR converts the two that were still hand-built overlays, and deletes the overlay code that the dialog makes redundant.

Why

Two modals were plain div overlays. The image modal was shown and hidden by inline onclick handlers that set style.display. It had no Escape key, no focus return to the image and no scroll lock. The Mermaid zoom view managed its own backdrop, Escape handling and stacking. Every other modal on the site is a <dialog>.

What

Mermaid fullscreen view

openFullscreenModal builds a <dialog class="mermaid-modal"> and calls showModal(). The browser handles Escape and focus return. The page scroll lock is released when the dialog closes, and a click on the backdrop closes it. Panning reuses the shared drag listeners.

Legacy image modal

ImageView.cshtml and ImageCarouselView.cshtml render a <dialog> with a method="dialog" close button instead of a div with inline handlers. One delegated listener in the new image-modal.ts opens it from [data-modal-id], and image-carousel.ts no longer carries its own click code. The design-system layout is unaffected: it has its own lightbox.

Tests

Vitest covers both modals (open as a modal, Escape and backdrop close, scroll restored). The ImageBlocks Razor snapshots in Elastic.Authoring.Tests take the new markup.

Verify

mise run site:test
dotnet test --project tests/Elastic.Authoring.Tests
mise run serve   # open /syntax/images and click an image; open /development/changelog-bundle-registry and use a diagram's fullscreen button

Check on the preview

  • Images — click an image: it opens centred over a dimmed page, and Escape, a click outside and the × all close it.
  • Changelog bundle registry — use a diagram's fullscreen button, then close it with Escape.

reakaleek and others added 3 commits November 19, 2026 21:51
The fullscreen view added its own document mousemove and mouseup listeners
on every open. The inline diagrams already share one pair, so the view uses
it too and has nothing to remove when it closes.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The view was a fixed div with its own z-index, Escape handler and backdrop
element. A modal dialog gives the top layer, Escape, focus trapping and focus
return to the expand button, and runtime/modal-escape.ts already covers it on
assembled pages. The dialog is the white box itself, styled with ::backdrop.
The page scroll lock stays: a modal dialog does not stop the page behind it
from scrolling.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The image modal was a div that inline onclick handlers showed and hid, with no
Escape key, no focus return and no scroll lock. It is now a dialog opened with
showModal(), so the browser handles Escape, focus and the backdrop. One
delegated listener in image-modal.ts replaces the inline handlers and the
carousel's own click code.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 19, 2026 20:52
@reakaleek
reakaleek requested a review from akira28 November 19, 2026 20:52
reakaleek and others added 4 commits November 19, 2026 22:00
A double quote in an image's alt text ended the aria-label attribute early and
corrupted the opening tag. Razor now encodes alt, the same way the carousel
template does. The two img alt attributes had the same flaw and get the same fix.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Escape mid-pan removes the dialog before any mouseup arrives. The shared drag
state kept pointing at the removed diagram, so later mouse moves still updated it.
The close handler now drops the drag that belongs to its own viewport.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A reader can open an image while a navigation request is in flight. The swap
then removes the dialog without a close event, and the destination page cannot
scroll until it reloads. A beforeSwap listener now closes open dialogs first, so
their close handlers release the scroll lock.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The legacy search renders in the page, beneath the top layer that an open image
or diagram dialog occupies. The shortcut was consumed and the search stayed
hidden. The handler now closes open zoom dialogs first.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The unit tests stub close(), so they pass even if Escape never dismisses a
dialog or focus never returns to the opener. The journey runs in Chrome. It
checks that Escape and the close button dismiss the image dialog, that the page
scroll lock lifts, and that focus returns to the opener for both the image and
the mermaid fullscreen view.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
click "a.image-reference[data-modal-id]"
expect attr "dialog.modal" open
click "dialog.modal[open] .close-button"
expect --not attr "dialog.modal" open

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Severity: P3 (Low)

Add an actual backdrop click to the browser journey. The unit tests dispatch a click directly on the dialog, so they still pass if CSS or hit testing routes an outside click elsewhere. This journey currently checks only Escape and the close button, leaving backdrop dismissal unverified in a browser.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No change in this PR. The journey runner (Nullean.Cdp.Journeys 0.13) cannot click a chosen point. It has no mouse verb, and click takes only a selector, which it clicks at the element's centre after checking that the element receives it. A point on the backdrop belongs to no element the dialog does not contain, and the centre of every ancestor I tried is off-screen on this page, where the dialog locks the scroll. I tried mouse, click <x> <y>, click --position, --force, and clicking body, main, #markdown-content and #pages-nav. The last one confirms the browser side: the runner reports that the <dialog> would receive a click at that point, which is the target the handler tests for. A drag that ends on the backdrop would pass, but it fires a different path (click on the common ancestor) and would not prove an outside click works. Unit tests still cover the handler, and the journey covers Escape, the × button and focus return. A coordinate click verb in the runner would close this gap.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That’s a useful correction. The implementation closes only when the click event’s target is the dialog itself (image-modal.ts, lines 8–14), so a selector click on an ancestor that is intercepted by the dialog would not verify the backdrop path. The journey currently covers Escape and the close button, not a backdrop click (image-zoom.journey, lines 17–22). I can’t independently verify the runner’s reported limitations from this repository, but given those constraints, I agree there isn’t a valid selector-only workaround to insist on in this PR; the browser-level coverage gap remains.

Generated by Libra. React with 👍 or 👎 to give feedback on this comment.

The beforeSwap listener closed every open zoom dialog, including for error
responses that htmx does not swap. It now skips a response with shouldSwap false
and closes only the dialogs inside the swap target.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The diagram dialog lives in body, outside the content htmx replaces, so closing
only the dialogs inside the swap target missed it. The dialog now records the
diagram that opened it, and a swap closes it when that diagram is in the target.
A swap of another part of the page leaves it open.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

@reakaleek
reakaleek merged commit 25fec59 into main Nov 19, 2026
44 checks passed
@reakaleek
reakaleek deleted the modals-native-dialog branch November 19, 2026 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant