Repository navigation
Open the image and diagram zoom views in native dialogs - #4966
Conversation
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]>
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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]>
Docs preview (local build)Handbook preview: https://docs-v3-preview.elastic.dev/elastic/docs-builder/pull/4966/ Sample changed pages: |
The Mermaid fullscreen view and the legacy image modal are now native
<dialog>elements opened withshowModal(), 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
divoverlays. The image modal was shown and hidden by inlineonclickhandlers that setstyle.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
openFullscreenModalbuilds a<dialog class="mermaid-modal">and callsshowModal(). 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.cshtmlandImageCarouselView.cshtmlrender a<dialog>with amethod="dialog"close button instead of adivwith inline handlers. One delegated listener in the newimage-modal.tsopens it from[data-modal-id], andimage-carousel.tsno 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
ImageBlocksRazor snapshots inElastic.Authoring.Teststake the new markup.Verify
Check on the preview