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/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..75a046465e
--- /dev/null
+++ b/src/Elastic.Documentation.Site/Assets/image-modal.test.ts
@@ -0,0 +1,141 @@
+import { bindImageModals } from './image-modal'
+
+// The markup ImageView.cshtml renders for one image.
+const image = `
+
+
+
+`
+
+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('')
+ })
+
+ 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')
+
+ 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)
+ 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..b5096e4b8e
--- /dev/null
+++ b/src/Elastic.Documentation.Site/Assets/image-modal.ts
@@ -0,0 +1,73 @@
+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 }
+ )
+}
+
+// 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) => {
+ const opener = openers.get(dialog)
+ if (scope.contains(dialog) || (opener && scope.contains(opener)))
+ 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) => {
+ 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)
+ })
+ document.addEventListener('htmx:beforeSwap', closeDialogsTheSwapRemoves)
+}
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/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 f68c20c01a..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 {
@@ -110,3 +111,147 @@ describe('mermaid pan', () => {
).toEqual([])
})
})
+
+describe('mermaid fullscreen', () => {
+ const modalViewport = () =>
+ document.querySelector('.mermaid-modal-viewport') as HTMLElement
+ const modalRendered = () =>
+ modalViewport().querySelector('.mermaid-rendered') as HTMLElement
+ const dialog = () =>
+ 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
+ ) {
+ this.setAttribute('open', '')
+ }
+ HTMLDialogElement.prototype.close = function (this: HTMLDialogElement) {
+ this.removeAttribute('open')
+ this.dispatchEvent(new Event('close'))
+ }
+ })
+
+ function openFullscreen(name: string) {
+ document
+ .querySelector(`#${name} .mermaid-fullscreen`)!
+ .click()
+ }
+
+ afterEach(() => {
+ // 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', () => {
+ 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([])
+ })
+
+ 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('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('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()
+ 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 4bb8e402f0..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,13 +206,10 @@ function calculateFitScale(
/**
* Open fullscreen modal with the diagram
*/
-function openFullscreenModal(imgSrc: string): void {
- // Create modal elements
- const modal = document.createElement('div')
+function openFullscreenModal(imgSrc: string, opener: Element): void {
+ 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 +228,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 = {
@@ -242,8 +239,6 @@ function openFullscreenModal(imgSrc: string): void {
startX: 0,
startY: 0,
}
- let isDragging = false
-
// Store initial zoom for reset
let initialZoom = 1
@@ -270,7 +265,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', () => {
@@ -297,30 +292,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
@@ -338,37 +316,24 @@ function openFullscreenModal(imgSrc: string): void {
}
})
- // Close modal function
- const closeModal = () => {
- document.removeEventListener('mousemove', onMouseMove)
- document.removeEventListener('mouseup', onMouseUp)
- 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', () => {
+ // 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()
+ })
- // Add modal to document
+ anchorZoomDialog(modal, opener)
document.body.appendChild(modal)
+ modal.showModal()
// Calculate and apply initial zoom to fit diagram in viewport
requestAnimationFrame(() => {
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.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()
}
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);
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..c6fef4030a 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.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(
"""
-
-
-
-
+
+ """
);
}
@@ -73,44 +71,40 @@ public class SupportsUrlPathPrefix : GeneratorTest
public async Task RendersHtml() =>
await Docs.ConvertsToHtml(
"""
-
-
-
-
+
+ """
);
[Test, DisplayName("renders HTML")]
public async Task RendersHtmlOfFolderRelative() =>
await Docs.Converts("folder/relative.md").ToHtml(
"""
-
-
-
-
+
+ """
);
[Test, DisplayName("has no errors")]
@@ -140,22 +134,20 @@ public class ImageRefOutOfScope : GeneratorTest
public async Task RendersHtml() =>
await Docs.ConvertsToHtml(
"""
-
-
-
-
+
+ """
);
[Test, DisplayName("reports diagnostics")]
@@ -191,37 +183,35 @@ 1. Customize the lifecycle.
public async Task RendersHtml() =>
await Docs.ConvertsToHtml(
"""
-
-
-
-
-
- -
-
Customize the lifecycle.
-
-
-
-
-
- """
+ """
);
}
@@ -238,21 +228,19 @@ public class EmptyAltText : MarkdownTest
public async Task RendersHtml() =>
await Docs.ConvertsToHtml(
"""
-
-
-
-
+
+ """
);
}
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"
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(
+ """
+
+
+
+
+ """
+ );
+}
+
[InheritsTests]
public class ImageScreenshotInsideListInAppliesSwitchTests() : DirectiveTest(
"""