From 54301a4a05336442bdc4dd88af86d5ed2b034b94 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 20:55:53 +0100 Subject: [PATCH 01/10] Pan the mermaid fullscreen view with the shared drag listeners 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 --- .../Assets/mermaid.test.ts | 39 +++++++++++++++++++ .../Assets/mermaid.ts | 23 +---------- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts index f68c20c01a..321062db22 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts @@ -110,3 +110,42 @@ describe('mermaid pan', () => { ).toEqual([]) }) }) + +describe('mermaid fullscreen', () => { + const modalViewport = () => + document.querySelector('.mermaid-modal-viewport') as HTMLElement + const modalRendered = () => + modalViewport().querySelector('.mermaid-rendered') as HTMLElement + + function openFullscreen(name: string) { + document + .querySelector(`#${name} .mermaid-fullscreen`)! + .click() + } + + afterEach(() => { + document.body.innerHTML = '' + }) + + it('pans the fullscreen diagram without adding document listeners', () => { + document.body.innerHTML = diagram('a') + initMermaid() + const added = vi.spyOn(document, 'addEventListener') + + openFullscreen('a') + press(modalViewport(), 10, 10) + move(40, 25) + release() + move(90, 90) + + expect(modalRendered().style.transform).toBe( + 'scale(1) translate(30px, 15px)' + ) + expect(rendered('a').style.transform).toBe('') + expect( + added.mock.calls + .map(([type]) => type) + .filter((type) => type === 'mousemove' || type === 'mouseup') + ).toEqual([]) + }) +}) diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.ts b/src/Elastic.Documentation.Site/Assets/mermaid.ts index 4bb8e402f0..1c511b1bf4 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.ts @@ -242,8 +242,6 @@ function openFullscreenModal(imgSrc: string): void { startX: 0, startY: 0, } - let isDragging = false - // Store initial zoom for reset let initialZoom = 1 @@ -297,30 +295,13 @@ function openFullscreenModal(imgSrc: string): void { // Modal pan handlers viewport.addEventListener('mousedown', (e: MouseEvent) => { if (e.button !== 0) return - isDragging = true state.startX = e.clientX - state.panX * state.zoom state.startY = e.clientY - state.panY * state.zoom viewport.classList.add('is-dragging') + drag = { state, viewport, rendered } e.preventDefault() }) - const onMouseMove = (e: MouseEvent) => { - if (!isDragging) return - state.panX = (e.clientX - state.startX) / state.zoom - state.panY = (e.clientY - state.startY) / state.zoom - applyTransform(rendered, state) - } - - const onMouseUp = () => { - if (isDragging) { - isDragging = false - viewport.classList.remove('is-dragging') - } - } - - document.addEventListener('mousemove', onMouseMove) - document.addEventListener('mouseup', onMouseUp) - // Modal wheel zoom viewport.addEventListener('wheel', (e: WheelEvent) => { if (!e.ctrlKey && !e.metaKey) return @@ -340,8 +321,6 @@ function openFullscreenModal(imgSrc: string): void { // Close modal function const closeModal = () => { - document.removeEventListener('mousemove', onMouseMove) - document.removeEventListener('mouseup', onMouseUp) unlockScroll() modal.remove() } From 7334bdef060ccdb9c4c815284c4bf5b951b191a8 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 20:57:53 +0100 Subject: [PATCH 02/10] Open the mermaid fullscreen view in a native dialog 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 --- .../Assets/markdown/mermaid.css | 36 +++++----- .../Assets/mermaid.test.ts | 70 ++++++++++++++++++- .../Assets/mermaid.ts | 46 ++++-------- .../Components/Markdown/Mermaid/mermaid.css | 27 +++---- 4 files changed, 116 insertions(+), 63 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/markdown/mermaid.css b/src/Elastic.Documentation.Site/Assets/markdown/mermaid.css index 8dd77c0106..22d4f4d9b3 100644 --- a/src/Elastic.Documentation.Site/Assets/markdown/mermaid.css +++ b/src/Elastic.Documentation.Site/Assets/markdown/mermaid.css @@ -86,12 +86,26 @@ /* Fullscreen modal */ .mermaid-modal { - position: fixed; - inset: 0; - z-index: 9999; + width: 95vw; + height: 95vh; + max-width: none; + max-height: none; + margin: auto; + padding: 0; + border: 0; + background-color: #ffffff; + border-radius: 0.75rem; + box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); + overflow: hidden; + animation: mermaid-fade-in 0.2s ease; +} + +.mermaid-modal[open] { display: flex; - align-items: center; - justify-content: center; + flex-direction: column; +} + +.mermaid-modal::backdrop { background-color: rgba(0, 0, 0, 0.5); animation: mermaid-fade-in 0.2s ease; } @@ -105,18 +119,6 @@ } } -.mermaid-modal-content { - position: relative; - width: 95vw; - height: 95vh; - background-color: #ffffff; - border-radius: 0.75rem; - box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25); - overflow: hidden; - display: flex; - flex-direction: column; -} - .mermaid-modal-close { position: absolute; top: 0.75rem; diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts index 321062db22..8e2271b1a7 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts @@ -116,6 +116,21 @@ describe('mermaid fullscreen', () => { document.querySelector('.mermaid-modal-viewport') as HTMLElement const modalRendered = () => modalViewport().querySelector('.mermaid-rendered') as HTMLElement + const dialog = () => + document.querySelector('dialog.mermaid-modal') + + beforeAll(() => { + // jsdom has no modal dialogs; these do what the browser does to the attribute and events. + HTMLDialogElement.prototype.showModal = function ( + this: HTMLDialogElement + ) { + this.setAttribute('open', '') + } + HTMLDialogElement.prototype.close = function (this: HTMLDialogElement) { + this.removeAttribute('open') + this.dispatchEvent(new Event('close')) + } + }) function openFullscreen(name: string) { document @@ -124,7 +139,8 @@ describe('mermaid fullscreen', () => { } afterEach(() => { - document.body.innerHTML = '' + // A test that leaves the dialog open leaves the page scroll locked. + document.documentElement.removeAttribute('style') }) it('pans the fullscreen diagram without adding document listeners', () => { @@ -148,4 +164,56 @@ describe('mermaid fullscreen', () => { .filter((type) => type === 'mousemove' || type === 'mouseup') ).toEqual([]) }) + + it('opens the diagram in a modal dialog that locks the page scroll', () => { + document.body.innerHTML = diagram('a') + initMermaid() + const showModal = vi.spyOn(HTMLDialogElement.prototype, 'showModal') + + openFullscreen('a') + + expect(showModal).toHaveBeenCalledTimes(1) + expect(dialog()?.open).toBe(true) + expect(modalRendered().querySelector('img')?.src).toContain('a.svg') + expect(document.documentElement.style.overflow).toBe('hidden') + }) + + it('closes on the close button', () => { + document.body.innerHTML = diagram('a') + initMermaid() + openFullscreen('a') + expect(dialog()?.open).toBe(true) + + document + .querySelector('.mermaid-modal-close')! + .click() + + expect(dialog()).toBeNull() + expect(document.documentElement.style.overflow).toBe('') + }) + + it('closes on a click on the backdrop, and stays open for a click inside', () => { + document.body.innerHTML = diagram('a') + initMermaid() + openFullscreen('a') + + modalViewport().dispatchEvent( + new MouseEvent('click', { bubbles: true }) + ) + expect(dialog()?.open).toBe(true) + + dialog()!.dispatchEvent(new MouseEvent('click', { bubbles: true })) + expect(dialog()).toBeNull() + }) + + it('cleans up when the browser closes it, as it does on Escape', () => { + document.body.innerHTML = diagram('a') + initMermaid() + openFullscreen('a') + + dialog()!.close() + + expect(dialog()).toBeNull() + expect(document.documentElement.style.overflow).toBe('') + }) }) diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.ts b/src/Elastic.Documentation.Site/Assets/mermaid.ts index 1c511b1bf4..426e7e4d02 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.ts @@ -206,12 +206,9 @@ function calculateFitScale( * Open fullscreen modal with the diagram */ function openFullscreenModal(imgSrc: string): void { - // Create modal elements - const modal = document.createElement('div') + const modal = document.createElement('dialog') modal.className = 'mermaid-modal' - - const modalContent = document.createElement('div') - modalContent.className = 'mermaid-modal-content' + modal.setAttribute('aria-label', 'Mermaid diagram') const closeBtn = document.createElement('button') closeBtn.type = 'button' @@ -230,9 +227,8 @@ function openFullscreenModal(imgSrc: string): void { rendered.appendChild(modalImg) viewport.appendChild(rendered) - modalContent.appendChild(closeBtn) - modalContent.appendChild(viewport) - modal.appendChild(modalContent) + modal.appendChild(closeBtn) + modal.appendChild(viewport) // State for modal zoom/pan - initial zoom will be calculated after mount const state: DiagramState = { @@ -268,7 +264,7 @@ function openFullscreenModal(imgSrc: string): void { controls.appendChild(zoomInBtn) controls.appendChild(zoomOutBtn) controls.appendChild(resetBtn) - modalContent.appendChild(controls) + modal.appendChild(controls) // Modal zoom handlers zoomInBtn.addEventListener('click', () => { @@ -319,35 +315,21 @@ function openFullscreenModal(imgSrc: string): void { } }) - // Close modal function - const closeModal = () => { - unlockScroll() - modal.remove() - } - - // Close on button click - closeBtn.addEventListener('click', closeModal) - - // Close on backdrop click + closeBtn.addEventListener('click', () => modal.close()) + // A click on the backdrop lands on the dialog itself; the viewport fills the rest of it. modal.addEventListener('click', (e: MouseEvent) => { - if (e.target === modal) { - closeModal() - } + if (e.target === modal) modal.close() }) - // Close on Escape key - const onKeyDown = (e: KeyboardEvent) => { - if (e.key === 'Escape') { - closeModal() - document.removeEventListener('keydown', onKeyDown) - } - } - document.addEventListener('keydown', onKeyDown) - + // The dialog handles Escape and returns focus to the opener; the page behind it would still scroll. const unlockScroll = lockPageScroll() + modal.addEventListener('close', () => { + unlockScroll() + modal.remove() + }) - // Add modal to document document.body.appendChild(modal) + modal.showModal() // Calculate and apply initial zoom to fit diagram in viewport requestAnimationFrame(() => { diff --git a/src/Elastic.Documentation.Site/Components/Markdown/Mermaid/mermaid.css b/src/Elastic.Documentation.Site/Components/Markdown/Mermaid/mermaid.css index 6bf1dd1649..a9232faa50 100644 --- a/src/Elastic.Documentation.Site/Components/Markdown/Mermaid/mermaid.css +++ b/src/Elastic.Documentation.Site/Components/Markdown/Mermaid/mermaid.css @@ -78,27 +78,28 @@ } .mermaid-modal { - position: fixed; - inset: 0; - z-index: var(--z-modal); - display: flex; - align-items: center; - justify-content: center; - background: color-mix(in oklab, var(--color-emphasis) 60%, transparent); -} - -.mermaid-modal-content { - position: relative; - display: flex; - flex-direction: column; width: 95vw; height: 95vh; + max-width: none; + max-height: none; + margin: auto; + padding: 0; overflow: hidden; + border: 0; border-radius: var(--radius-lg); background: var(--color-surface); box-shadow: var(--shadow-overlay); } +.mermaid-modal[open] { + display: flex; + flex-direction: column; +} + +.mermaid-modal::backdrop { + background: color-mix(in oklab, var(--color-emphasis) 60%, transparent); +} + .mermaid-modal-close { position: absolute; top: var(--space-3); From 2b72476b0305c3d8af2f6bbde590aa48a5deb1e9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 21:51:27 +0100 Subject: [PATCH 03/10] Open the legacy image modal in a native dialog 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 --- .../Assets/image-carousel.ts | 17 -- .../Assets/image-modal.test.ts | 104 ++++++++++ .../Assets/image-modal.ts | 39 ++++ src/Elastic.Documentation.Site/Assets/main.ts | 2 + .../Assets/markdown/image-carousel.css | 36 ---- .../Assets/modal.css | 30 +-- .../Directives/Image/ImageCarouselView.cshtml | 14 +- .../Myst/Directives/Image/ImageView.cshtml | 16 +- .../Blocks/ImageBlocks.cs | 196 ++++++++---------- 9 files changed, 259 insertions(+), 195 deletions(-) create mode 100644 src/Elastic.Documentation.Site/Assets/image-modal.test.ts create mode 100644 src/Elastic.Documentation.Site/Assets/image-modal.ts diff --git a/src/Elastic.Documentation.Site/Assets/image-carousel.ts b/src/Elastic.Documentation.Site/Assets/image-carousel.ts index 0091e65773..1ebb2a5dc0 100644 --- a/src/Elastic.Documentation.Site/Assets/image-carousel.ts +++ b/src/Elastic.Documentation.Site/Assets/image-carousel.ts @@ -70,23 +70,6 @@ class ImageCarousel { indicator.addEventListener('click', () => this.goToSlide(index)) }) - // Handle image clicks for modal - this.slides.forEach((slide) => { - const imageLink = slide.querySelector('.carousel-image-reference') - if (imageLink) { - imageLink.addEventListener('click', (e) => { - e.preventDefault() - const modalId = imageLink.getAttribute('data-modal-id') - if (modalId) { - const modal = document.getElementById(modalId) - if (modal) { - modal.style.display = 'flex' - } - } - }) - } - }) - // Keyboard navigation document.addEventListener('keydown', (e) => { if (!this.isInViewport()) return diff --git a/src/Elastic.Documentation.Site/Assets/image-modal.test.ts b/src/Elastic.Documentation.Site/Assets/image-modal.test.ts new file mode 100644 index 0000000000..909f1b6145 --- /dev/null +++ b/src/Elastic.Documentation.Site/Assets/image-modal.test.ts @@ -0,0 +1,104 @@ +import { bindImageModals } from './image-modal' + +// The markup ImageView.cshtml renders for one image. +const image = ` + + A + + + +` + +const dialog = () => document.getElementById('modal-a') as HTMLDialogElement +const scroll = () => document.documentElement.style.overflow + +function click(target: Element): MouseEvent { + const event = new MouseEvent('click', { bubbles: true, cancelable: true }) + target.dispatchEvent(event) + return event +} + +describe('legacy image modal', () => { + beforeAll(() => { + bindImageModals() + // jsdom has no modal dialogs; these do what the browser does to the attribute and events. + HTMLDialogElement.prototype.showModal = function ( + this: HTMLDialogElement + ) { + this.setAttribute('open', '') + } + HTMLDialogElement.prototype.close = function (this: HTMLDialogElement) { + if (!this.open) return + this.removeAttribute('open') + this.dispatchEvent(new Event('close')) + } + }) + + beforeEach(() => { + document.body.innerHTML = image + }) + + afterEach(() => { + // A test that leaves the dialog open leaves the page scroll locked. + document.documentElement.removeAttribute('style') + }) + + it('opens the image in a modal dialog that locks the page scroll', () => { + const showModal = vi.spyOn(HTMLDialogElement.prototype, 'showModal') + + const event = click(document.querySelector('img')!) + + expect(event.defaultPrevented).toBe(true) + expect(showModal).toHaveBeenCalledTimes(1) + expect(dialog().open).toBe(true) + expect(scroll()).toBe('hidden') + }) + + it('closes on a click on the backdrop, and stays open for a click inside', () => { + click(document.querySelector('[data-modal-id]')!) + + click(dialog().querySelector('img')!) + expect(dialog().open).toBe(true) + + click(dialog()) + expect(dialog().open).toBe(false) + expect(scroll()).toBe('') + }) + + it('unlocks the page scroll when the browser closes it, as it does on Escape', () => { + click(document.querySelector('[data-modal-id]')!) + + dialog().close() + + expect(scroll()).toBe('') + }) + + it('opens and closes again after a close', () => { + const opener = document.querySelector('[data-modal-id]')! + click(opener) + dialog().close() + + click(opener) + expect(dialog().open).toBe(true) + expect(scroll()).toBe('hidden') + click(dialog()) + expect(dialog().open).toBe(false) + expect(scroll()).toBe('') + }) + + it('opens the dialog of a carousel slide', () => { + document.body.innerHTML = ` +${image}` + + click(document.querySelector('.carousel-image-reference img')!) + + expect(dialog().open).toBe(true) + }) +}) diff --git a/src/Elastic.Documentation.Site/Assets/image-modal.ts b/src/Elastic.Documentation.Site/Assets/image-modal.ts new file mode 100644 index 0000000000..9b8d06aeea --- /dev/null +++ b/src/Elastic.Documentation.Site/Assets/image-modal.ts @@ -0,0 +1,39 @@ +import { lockPageScroll } from './scroll-lock' + +function open(dialog: HTMLDialogElement): void { + dialog.showModal() + // The dialog handles Escape and returns focus to the image; the page behind it would still scroll. + const unlockScroll = lockPageScroll() + const closing = new AbortController() + // A click on the backdrop lands on the dialog itself, not on its content. + dialog.addEventListener( + 'click', + (event) => { + if (event.target === dialog) dialog.close() + }, + { signal: closing.signal } + ) + dialog.addEventListener( + 'close', + () => { + unlockScroll() + closing.abort() + }, + { signal: closing.signal } + ) +} + +// Opens the dialog named by [data-modal-id] on an image link. One document listener serves every page htmx swaps in. +export function bindImageModals(): void { + document.addEventListener('click', (event) => { + const link = + event.target instanceof Element + ? event.target.closest('[data-modal-id]') + : null + if (!link) return + const dialog = document.getElementById(link.dataset.modalId ?? '') + if (!(dialog instanceof HTMLDialogElement)) return + event.preventDefault() + open(dialog) + }) +} diff --git a/src/Elastic.Documentation.Site/Assets/main.ts b/src/Elastic.Documentation.Site/Assets/main.ts index 8810441af5..0bb576f1c5 100644 --- a/src/Elastic.Documentation.Site/Assets/main.ts +++ b/src/Elastic.Documentation.Site/Assets/main.ts @@ -9,6 +9,7 @@ import { config } from './config' import { initCopyButton } from './copybutton' import { initHighlight, preloadHighlight } from './hljs' import { initImageCarousel } from './image-carousel' +import { bindImageModals } from './image-modal' import { initListing } from './listing' import { initMath } from './math' import { initMermaid } from './mermaid' @@ -91,6 +92,7 @@ initApiMenus() initApiChromeSync() bindApiBetaBanner() bindModalEscape() +bindImageModals() bindHtmxHooks({ forcesFullPageLoad: (targetPath) => // A move between a docs page and an API page, or to another API product: the swap would diff --git a/src/Elastic.Documentation.Site/Assets/markdown/image-carousel.css b/src/Elastic.Documentation.Site/Assets/markdown/image-carousel.css index e19cce1ec7..acabd456f2 100644 --- a/src/Elastic.Documentation.Site/Assets/markdown/image-carousel.css +++ b/src/Elastic.Documentation.Site/Assets/markdown/image-carousel.css @@ -116,42 +116,6 @@ padding-bottom: 40px; /* Space for indicators */ } -/* Override modal styles for image carousels */ -.modal .modal-content { - max-width: 95vw !important; - max-height: 95vh !important; - width: auto !important; - height: auto !important; - padding: 0 !important; - background: transparent !important; - box-shadow: none !important; -} - -.modal .modal-content img { - max-width: 95vw; - max-height: 95vh; - width: auto; - height: auto; - object-fit: contain; - display: block; -} - -/* Ensure the close button is visible */ -.modal .modal-close { - background: rgba(0, 0, 0, 0.7); - border-radius: 50%; - width: 40px; - height: 40px; - display: flex; - align-items: center; - justify-content: center; - top: -20px; - right: -20px; -} - -.modal .modal-close a { - color: white; -} @media (max-width: 768px) { .carousel-control { width: 30px; diff --git a/src/Elastic.Documentation.Site/Assets/modal.css b/src/Elastic.Documentation.Site/Assets/modal.css index 207742cde0..6de4a0d0d9 100644 --- a/src/Elastic.Documentation.Site/Assets/modal.css +++ b/src/Elastic.Documentation.Site/Assets/modal.css @@ -1,32 +1,24 @@ -.modal { - @apply fixed inset-0 z-50 flex hidden items-center justify-center bg-black/50; -} +dialog.modal { + @apply m-auto max-h-none max-w-none overflow-visible border-0 bg-transparent p-0; -.modal-content { - @apply relative w-full max-w-3xl items-center rounded-lg bg-white p-6 shadow-lg; + &::backdrop { + background: rgba(0, 0, 0, 0.5); + } } -.modal-content figure { - @apply text-center; +.modal-content { + @apply relative; } .modal-content img { - @apply mx-auto h-auto max-w-full rounded-lg; -} - -.modal-content figcaption { - @apply mt-4 text-sm; -} - -.modal-footer { - @apply mt-4 text-right; + @apply mx-auto block h-auto max-h-[95vh] w-auto max-w-[95vw] rounded-lg object-contain; } .modal-close { - @apply absolute top-2 right-4 cursor-pointer transition-colors; + @apply absolute -top-5 -right-5 flex h-10 w-10 items-center justify-center rounded-full bg-black/70; - & > a { - @apply text-ink-dark hover:text-ink text-2xl font-bold no-underline; + & > button { + @apply cursor-pointer text-2xl font-bold text-white; } } diff --git a/src/Elastic.Markdown/Myst/Directives/Image/ImageCarouselView.cshtml b/src/Elastic.Markdown/Myst/Directives/Image/ImageCarouselView.cshtml index 959a60022b..9aeffe50de 100644 --- a/src/Elastic.Markdown/Myst/Directives/Image/ImageCarouselView.cshtml +++ b/src/Elastic.Markdown/Myst/Directives/Image/ImageCarouselView.cshtml @@ -58,18 +58,14 @@ @for (int i = 0; i < Model.Images.Count; i++) { var image = Model.Images[i]; - + } diff --git a/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml b/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml index d7587c422f..260434a048 100644 --- a/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml +++ b/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml @@ -1,21 +1,17 @@ @using Elastic.Documentation.Extensions @inherits RazorSlice - + @(Model.Alt == string.Empty ? HtmlString.Empty : new HtmlString(Model.Alt)) @Model.RenderBlock() - + diff --git a/tests/Elastic.Authoring.Tests/Blocks/ImageBlocks.cs b/tests/Elastic.Authoring.Tests/Blocks/ImageBlocks.cs index 663a84b370..9bf162f2c7 100644 --- a/tests/Elastic.Authoring.Tests/Blocks/ImageBlocks.cs +++ b/tests/Elastic.Authoring.Tests/Blocks/ImageBlocks.cs @@ -21,22 +21,20 @@ public class StaticPathToImage : MarkdownTest public async Task RendersHtml() => await Docs.ConvertsToHtml( """ - - Elasticsearch - - + + """ ); } @@ -73,44 +71,40 @@ public class SupportsUrlPathPrefix : GeneratorTest public async Task RendersHtml() => await Docs.ConvertsToHtml( """ - - Elasticsearch - - + + """ ); [Test, DisplayName("renders HTML")] public async Task RendersHtmlOfFolderRelative() => await Docs.Converts("folder/relative.md").ToHtml( """ - - Elasticsearch - - + + """ ); [Test, DisplayName("has no errors")] @@ -140,22 +134,20 @@ public class ImageRefOutOfScope : GeneratorTest public async Task RendersHtml() => await Docs.ConvertsToHtml( """ - - Elasticsearch - - + + """ ); [Test, DisplayName("reports diagnostics")] @@ -191,37 +183,35 @@ 1. Customize the lifecycle. public async Task RendersHtml() => await Docs.ConvertsToHtml( """ -
- - -
-
    -
  1. -

    Customize the lifecycle.

    - - Elasticsearch - -
  2. -
+
+ + + +
- - """ + """ ); } @@ -238,21 +228,19 @@ public class EmptyAltText : MarkdownTest public async Task RendersHtml() => await Docs.ConvertsToHtml( """ - - - - + + """ ); } From d199ca7c1f3eca46feff24364df0eb11180bf8cf Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 22:00:35 +0100 Subject: [PATCH 04/10] Encode the alt text in the image dialog and its images 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 --- .../Myst/Directives/Image/ImageView.cshtml | 6 ++-- .../Directives/ImageTests.cs | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml b/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml index 260434a048..c6fef4030a 100644 --- a/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml +++ b/src/Elastic.Markdown/Myst/Directives/Image/ImageView.cshtml @@ -1,17 +1,17 @@ @using Elastic.Documentation.Extensions @inherits RazorSlice - @(Model.Alt == string.Empty ? HtmlString.Empty : new HtmlString(Model.Alt)) + @Model.Alt @Model.RenderBlock() - + diff --git a/tests/Elastic.Markdown.Tests/Directives/ImageTests.cs b/tests/Elastic.Markdown.Tests/Directives/ImageTests.cs index ca0389a0de..aec33c4a89 100644 --- a/tests/Elastic.Markdown.Tests/Directives/ImageTests.cs +++ b/tests/Elastic.Markdown.Tests/Directives/ImageTests.cs @@ -8,6 +8,7 @@ using Elastic.Documentation.Testing; using Elastic.Markdown.Myst.Directives.Image; using Nullean.Snapshots; +using Nullean.Snapshots.Html; namespace Elastic.Markdown.Tests.Directives; @@ -44,6 +45,36 @@ public void ImageIsFoundSoNoErrorIsEmitted() } } +[InheritsTests] +public class ImageAltWithQuoteTests() : DirectiveTest(""" +:::{image} img/observability.png +:alt: Say "hi" +::: +""") +{ + protected override void AddToFileSystem(MockFileSystem fileSystem) => fileSystem.AddFile(@"docs/img/observability.png", ""); + + [Test] + public void QuoteInAltStaysInsideTheAttributes() => + Html.Should().MatchInlineHtmlSnapshot( + """ + + Say "hi" + + + + + """ + ); +} + [InheritsTests] public class ImageScreenshotInsideListInAppliesSwitchTests() : DirectiveTest( """ From 58231e30cfac90595bf585f70fb4ccd94b2c0ca9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 22:01:04 +0100 Subject: [PATCH 05/10] Clear the pan state when the mermaid dialog closes 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 --- .../Assets/mermaid.test.ts | 14 ++++++++++++++ src/Elastic.Documentation.Site/Assets/mermaid.ts | 2 ++ 2 files changed, 16 insertions(+) diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts index 8e2271b1a7..ba2f7b2a44 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts @@ -206,6 +206,20 @@ describe('mermaid fullscreen', () => { expect(dialog()).toBeNull() }) + it('stops panning when the browser closes it mid-drag', () => { + document.body.innerHTML = diagram('a') + initMermaid() + openFullscreen('a') + const closing = modalRendered() + + press(modalViewport(), 10, 10) + move(40, 25) + dialog()!.close() + move(90, 90) + + expect(closing.style.transform).toBe('scale(1) translate(30px, 15px)') + }) + it('cleans up when the browser closes it, as it does on Escape', () => { document.body.innerHTML = diagram('a') initMermaid() diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.ts b/src/Elastic.Documentation.Site/Assets/mermaid.ts index 426e7e4d02..b9c1fc4ed3 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.ts @@ -324,6 +324,8 @@ function openFullscreenModal(imgSrc: string): void { // The dialog handles Escape and returns focus to the opener; the page behind it would still scroll. const unlockScroll = lockPageScroll() modal.addEventListener('close', () => { + // Escape mid-pan removes the dialog before any mouseup; the shared drag must not outlive it. + if (drag?.viewport === viewport) drag = null unlockScroll() modal.remove() }) From 507f32391fa5062b879f35a69bbde7439c2a1e39 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 22:01:33 +0100 Subject: [PATCH 06/10] Close open zoom dialogs before htmx swaps the page 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 --- .../Assets/image-modal.test.ts | 10 ++++++++++ src/Elastic.Documentation.Site/Assets/image-modal.ts | 11 +++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/Elastic.Documentation.Site/Assets/image-modal.test.ts b/src/Elastic.Documentation.Site/Assets/image-modal.test.ts index 909f1b6145..f020edcc88 100644 --- a/src/Elastic.Documentation.Site/Assets/image-modal.test.ts +++ b/src/Elastic.Documentation.Site/Assets/image-modal.test.ts @@ -78,6 +78,16 @@ describe('legacy image modal', () => { expect(scroll()).toBe('') }) + it('closes an open dialog and unlocks the page scroll before htmx swaps the page', () => { + click(document.querySelector('[data-modal-id]')!) + expect(scroll()).toBe('hidden') + + document.dispatchEvent(new Event('htmx:beforeSwap')) + + expect(dialog().open).toBe(false) + expect(scroll()).toBe('') + }) + it('opens and closes again after a close', () => { const opener = document.querySelector('[data-modal-id]')! click(opener) diff --git a/src/Elastic.Documentation.Site/Assets/image-modal.ts b/src/Elastic.Documentation.Site/Assets/image-modal.ts index 9b8d06aeea..3efceed13d 100644 --- a/src/Elastic.Documentation.Site/Assets/image-modal.ts +++ b/src/Elastic.Documentation.Site/Assets/image-modal.ts @@ -23,6 +23,15 @@ function open(dialog: HTMLDialogElement): void { ) } +// Closes every open image or diagram dialog; their close handlers release the scroll lock. +export function closeOpenZoomDialogs(): void { + document + .querySelectorAll( + 'dialog.modal[open], dialog.mermaid-modal[open]' + ) + .forEach((dialog) => dialog.close()) +} + // Opens the dialog named by [data-modal-id] on an image link. One document listener serves every page htmx swaps in. export function bindImageModals(): void { document.addEventListener('click', (event) => { @@ -36,4 +45,6 @@ export function bindImageModals(): void { event.preventDefault() open(dialog) }) + // A swap removes the dialog without firing its close event, which would leave the page scroll locked. + document.addEventListener('htmx:beforeSwap', closeOpenZoomDialogs) } From 7ecef02ad583c76a5da1d10a2722aafab8ee6a29 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 22:02:08 +0100 Subject: [PATCH 07/10] Close an open zoom dialog when Ctrl+K opens the search 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 --- .../ModalSearch/ModalSearch.test.tsx | 19 +++++++++++++++++++ .../ModalSearch/ModalSearch.tsx | 3 +++ 2 files changed, 22 insertions(+) diff --git a/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.test.tsx b/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.test.tsx index 5db9a6e872..c3de7df4cc 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.test.tsx +++ b/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.test.tsx @@ -73,6 +73,25 @@ describe('ModalSearch', () => { expect(closeButton()).not.toBeInTheDocument() }) + it('closes an open zoom dialog when Ctrl+K opens the search', () => { + renderModalSearch() + const zoom = document.createElement('dialog') + zoom.className = 'modal' + zoom.setAttribute('open', '') + zoom.close = vi.fn(() => zoom.removeAttribute('open')) + document.body.appendChild(zoom) + + act(() => { + window.dispatchEvent( + new KeyboardEvent('keydown', { key: 'k', ctrlKey: true }) + ) + }) + zoom.remove() + + expect(zoom.close).toHaveBeenCalledTimes(1) + expect(modalSearchStore.getState().isOpen).toBe(true) + }) + it('cancels a pending result navigation when the modal is dismissed', () => { renderModalSearch() diff --git a/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.tsx b/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.tsx index c5b9d6b83e..36aa67c963 100644 --- a/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.tsx +++ b/src/Elastic.Documentation.Site/Assets/web-components/ModalSearch/ModalSearch.tsx @@ -1,5 +1,6 @@ import { config } from '../../config' import '../../eui-icons-cache' +import { closeOpenZoomDialogs } from '../../image-modal' import { lockPageScroll } from '../../scroll-lock' import { ElasticAiAssistantButton } from '../AskAi/ElasticAiAssistantButton' import { InfoBanner } from '../AskAi/InfoBanner' @@ -380,6 +381,8 @@ export const ModalSearch = ({ const handleKeyDown = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === 'k') { e.preventDefault() + // This search renders in the page, under the top layer an open zoom dialog sits in. + closeOpenZoomDialogs() trackOpened('keyboard_shortcut') openModal() } From e982c8a052c556c40d50ae2f6859df6fa31b1f7e Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 22:07:56 +0100 Subject: [PATCH 08/10] Add a browser journey for the image and diagram zoom dialogs 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 --- docs/development/journeys.md | 2 +- .../content/image-zoom.verified.journey | 0 .../journeys/content/image-zoom.journey | 30 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/Elastic.Documentation.Journeys.Tests/.snapshots/journeys/content/image-zoom.verified.journey create mode 100644 tests/Elastic.Documentation.Journeys.Tests/journeys/content/image-zoom.journey diff --git a/docs/development/journeys.md b/docs/development/journeys.md index 701bd9e955..a0da880ac8 100644 --- a/docs/development/journeys.md +++ b/docs/development/journeys.md @@ -47,7 +47,7 @@ Each folder under `journeys/` is an area, and each area has one test class under |---|---| | `landing` | The home page, the 404 page, a hub page and a group of page cards | | `navigation` | The sidebar and the table of contents | -| `content` | Tabs, dropdowns, admonitions and the code copy button | +| `content` | Tabs, dropdowns, admonitions, the code copy button and the image and diagram zoom dialogs | | `chrome` | The isolated header (logo, search button, GitHub link, deployment info) and the footer | | `page-actions` | The "View as Markdown" and "Edit this page" links | | `feedback` | The "Was this page helpful?" buttons render with their accessible names (needs the `page-feedback` flag, which the isolated site only turns on in Debug builds) | diff --git a/tests/Elastic.Documentation.Journeys.Tests/.snapshots/journeys/content/image-zoom.verified.journey b/tests/Elastic.Documentation.Journeys.Tests/.snapshots/journeys/content/image-zoom.verified.journey new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/Elastic.Documentation.Journeys.Tests/journeys/content/image-zoom.journey b/tests/Elastic.Documentation.Journeys.Tests/journeys/content/image-zoom.journey new file mode 100644 index 0000000000..ea1d96935d --- /dev/null +++ b/tests/Elastic.Documentation.Journeys.Tests/journeys/content/image-zoom.journey @@ -0,0 +1,30 @@ +# @requires build-type:isolated +# The image and diagram zoom views are native dialogs: Escape and the close button dismiss them, focus returns to +# the control that opened them, and the page scrolls again. +set viewport 1280 800 +open /syntax/images +wait --load networkidle +expect --not attr "dialog.modal" open +expect --not visible "a.image-reference[data-modal-id]:focus" +click "a.image-reference[data-modal-id]" +expect attr "dialog.modal" open +expect attr "html" style "overflow: hidden;" --contains +press Escape +expect --not attr "dialog.modal" open +expect --not attr "html" style "overflow: hidden;" --contains +expect visible "a.image-reference[data-modal-id]:focus" + +# The × button dismisses it too. +click "a.image-reference[data-modal-id]" +expect attr "dialog.modal" open +click "dialog.modal[open] .close-button" +expect --not attr "dialog.modal" open + +# The diagram's fullscreen view. +open /syntax/diagrams +wait --load networkidle +click ".mermaid-container .mermaid-fullscreen" +expect visible "dialog.mermaid-modal[open]" +press Escape +expect --not attached "dialog.mermaid-modal" +expect visible ".mermaid-container .mermaid-fullscreen:focus" From 4279b8fd12efde8bbc534d597d9902feee00dfa5 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 22:10:14 +0100 Subject: [PATCH 09/10] Close only the zoom dialogs an htmx swap replaces 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 --- .../Assets/image-modal.test.ts | 31 +++++++++++++++++-- .../Assets/image-modal.ts | 19 +++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/image-modal.test.ts b/src/Elastic.Documentation.Site/Assets/image-modal.test.ts index f020edcc88..75a046465e 100644 --- a/src/Elastic.Documentation.Site/Assets/image-modal.test.ts +++ b/src/Elastic.Documentation.Site/Assets/image-modal.test.ts @@ -78,16 +78,43 @@ describe('legacy image modal', () => { expect(scroll()).toBe('') }) - it('closes an open dialog and unlocks the page scroll before htmx swaps the page', () => { + const beforeSwap = (detail: object) => + document.dispatchEvent(new CustomEvent('htmx:beforeSwap', { detail })) + + it('closes an open dialog and unlocks the page scroll before htmx swaps its page', () => { click(document.querySelector('[data-modal-id]')!) expect(scroll()).toBe('hidden') - document.dispatchEvent(new Event('htmx:beforeSwap')) + beforeSwap({ shouldSwap: true, target: document.body }) expect(dialog().open).toBe(false) expect(scroll()).toBe('') }) + it('keeps the dialog open for a response htmx does not swap', () => { + click(document.querySelector('[data-modal-id]')!) + + beforeSwap({ shouldSwap: false, target: document.body }) + + expect(dialog().open).toBe(true) + expect(scroll()).toBe('hidden') + }) + + it('keeps the dialog open when the swap replaces another part of the page', () => { + document.body.insertAdjacentHTML( + 'beforeend', + '
' + ) + click(document.querySelector('[data-modal-id]')!) + + beforeSwap({ + shouldSwap: true, + target: document.getElementById('elsewhere'), + }) + + expect(dialog().open).toBe(true) + }) + it('opens and closes again after a close', () => { const opener = document.querySelector('[data-modal-id]')! click(opener) diff --git a/src/Elastic.Documentation.Site/Assets/image-modal.ts b/src/Elastic.Documentation.Site/Assets/image-modal.ts index 3efceed13d..ba256a5bb3 100644 --- a/src/Elastic.Documentation.Site/Assets/image-modal.ts +++ b/src/Elastic.Documentation.Site/Assets/image-modal.ts @@ -23,15 +23,25 @@ function open(dialog: HTMLDialogElement): void { ) } -// Closes every open image or diagram dialog; their close handlers release the scroll lock. -export function closeOpenZoomDialogs(): void { - document +// Closes the open image or diagram dialogs inside scope; their close handlers release the scroll lock. +export function closeOpenZoomDialogs(scope: ParentNode = document): void { + scope .querySelectorAll( 'dialog.modal[open], dialog.mermaid-modal[open]' ) .forEach((dialog) => dialog.close()) } +type BeforeSwapDetail = { shouldSwap?: boolean; target?: Element } + +// A swap removes the dialogs inside its target without firing their close event, which would leave the page scroll +// locked. A response htmx will not swap, such as an error, leaves the page and its dialogs alone. +function closeDialogsTheSwapRemoves(event: Event): void { + const { shouldSwap, target } = + (event as CustomEvent).detail ?? {} + if (shouldSwap && target) closeOpenZoomDialogs(target) +} + // Opens the dialog named by [data-modal-id] on an image link. One document listener serves every page htmx swaps in. export function bindImageModals(): void { document.addEventListener('click', (event) => { @@ -45,6 +55,5 @@ export function bindImageModals(): void { event.preventDefault() open(dialog) }) - // A swap removes the dialog without firing its close event, which would leave the page scroll locked. - document.addEventListener('htmx:beforeSwap', closeOpenZoomDialogs) + document.addEventListener('htmx:beforeSwap', closeDialogsTheSwapRemoves) } From ed1ea2f62413bfe2393fc5a06f74c572883b56c9 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 19 Nov 2026 22:19:27 +0100 Subject: [PATCH 10/10] Close the diagram dialog when a swap removes its diagram 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 --- .../Assets/image-modal.ts | 22 +++++++++++++---- .../Assets/mermaid.test.ts | 24 +++++++++++++++++++ .../Assets/mermaid.ts | 6 +++-- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/src/Elastic.Documentation.Site/Assets/image-modal.ts b/src/Elastic.Documentation.Site/Assets/image-modal.ts index ba256a5bb3..b5096e4b8e 100644 --- a/src/Elastic.Documentation.Site/Assets/image-modal.ts +++ b/src/Elastic.Documentation.Site/Assets/image-modal.ts @@ -23,13 +23,27 @@ function open(dialog: HTMLDialogElement): void { ) } -// Closes the open image or diagram dialogs inside scope; their close handlers release the scroll lock. -export function closeOpenZoomDialogs(scope: ParentNode = document): void { - scope +// A diagram dialog lives in , outside the content a swap replaces, so it records the container that opened it. +const openers = new WeakMap() + +export function anchorZoomDialog( + dialog: HTMLDialogElement, + opener: Element +): void { + openers.set(dialog, opener) +} + +// Closes the open image or diagram dialogs that sit in scope or were opened from it; their close handlers release the scroll lock. +export function closeOpenZoomDialogs(scope: Node = document): void { + document .querySelectorAll( 'dialog.modal[open], dialog.mermaid-modal[open]' ) - .forEach((dialog) => dialog.close()) + .forEach((dialog) => { + const opener = openers.get(dialog) + if (scope.contains(dialog) || (opener && scope.contains(opener))) + dialog.close() + }) } type BeforeSwapDetail = { shouldSwap?: boolean; target?: Element } diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts index ba2f7b2a44..2529c07e0a 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.test.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.test.ts @@ -1,3 +1,4 @@ +import { bindImageModals } from './image-modal' import { initMermaid } from './mermaid' function diagram(name: string): string { @@ -120,6 +121,7 @@ describe('mermaid fullscreen', () => { document.querySelector('dialog.mermaid-modal') beforeAll(() => { + bindImageModals() // jsdom has no modal dialogs; these do what the browser does to the attribute and events. HTMLDialogElement.prototype.showModal = function ( this: HTMLDialogElement @@ -220,6 +222,28 @@ describe('mermaid fullscreen', () => { expect(closing.style.transform).toBe('scale(1) translate(30px, 15px)') }) + it('closes with the diagram it was opened from when htmx swaps that page, but not for another swap', () => { + document.body.innerHTML = + '
' + + diagram('a') + + '
' + initMermaid() + openFullscreen('a') + const swap = (target: Element) => + document.dispatchEvent( + new CustomEvent('htmx:beforeSwap', { + detail: { shouldSwap: true, target }, + }) + ) + + swap(document.getElementById('elsewhere')!) + expect(dialog()?.open).toBe(true) + + swap(document.getElementById('main-container')!) + expect(dialog()).toBeNull() + expect(document.documentElement.style.overflow).toBe('') + }) + it('cleans up when the browser closes it, as it does on Escape', () => { document.body.innerHTML = diagram('a') initMermaid() diff --git a/src/Elastic.Documentation.Site/Assets/mermaid.ts b/src/Elastic.Documentation.Site/Assets/mermaid.ts index b9c1fc4ed3..e7d7b88952 100644 --- a/src/Elastic.Documentation.Site/Assets/mermaid.ts +++ b/src/Elastic.Documentation.Site/Assets/mermaid.ts @@ -1,4 +1,5 @@ import { fullscreenIcon } from './icons' +import { anchorZoomDialog } from './image-modal' import { lockPageScroll } from './scroll-lock' // Zoom configuration @@ -150,7 +151,7 @@ function setupControls( // Fullscreen handler fullscreenBtn.addEventListener('click', () => { - openFullscreenModal(imgSrc) + openFullscreenModal(imgSrc, container) }) // Pan with mouse drag @@ -205,7 +206,7 @@ function calculateFitScale( /** * Open fullscreen modal with the diagram */ -function openFullscreenModal(imgSrc: string): void { +function openFullscreenModal(imgSrc: string, opener: Element): void { const modal = document.createElement('dialog') modal.className = 'mermaid-modal' modal.setAttribute('aria-label', 'Mermaid diagram') @@ -330,6 +331,7 @@ function openFullscreenModal(imgSrc: string): void { modal.remove() }) + anchorZoomDialog(modal, opener) document.body.appendChild(modal) modal.showModal()