diff --git a/docs/development/design-system.md b/docs/development/design-system.md
index 9edaceac16..6b57920f1f 100644
--- a/docs/development/design-system.md
+++ b/docs/development/design-system.md
@@ -161,10 +161,10 @@ These replace React components built on EUI. Each renders complete markup on the
| Piece | Replaces | How it works |
|---|---|---|
-| Applies-to badge | `applies-to-popover` | A native `details` element holds the panel. Script moves the open panel into the browser's top layer, next to its trigger, so no ancestor can clip it |
+| Applies-to badge | `applies-to-popover` | A button and a panel. `Assets/ds/applies-popover.ts` gives the panel an id and makes it a popover the button opens, in the browser's top layer, so no ancestor can clip it. Unbound, the panel shows while the button has focus |
| Search | The modal search in the header | A native `dialog`, opened by the header field or `Ctrl+K`. Isolated builds query the Pagefind index and assembled builds query the search API. Results are drawn from a template, and highlights are built from text nodes |
| Page feedback | `page-feedback` | The server renders the whole widget, hidden. Script reveals it, keeps a draft in `sessionStorage` and sends the same payload as before |
-| Version and section pickers | `version-dropdown` | A native `details` menu of plain links |
+| Version and section pickers | `version-dropdown` | A link menu: a button that opens a popover of plain links |
| Vector sizing calculator | `vector-sizing-calculator` | The server renders the whole form, hidden, with native inputs, `datalist` presets and a `details` for advanced settings. `Assets/ds/vector-sizing.ts` reveals it and reuses the existing calculation modules for the arithmetic |
| Ask AI | The React assistant | A button and a native `dialog` side panel. `Assets/ds/ask-ai.ts` streams the answer from the same endpoint as before and renders it as sanitized Markdown. Shown on assembler and Codex pages. Suggestions come from the existing assistant configuration, the conversation is kept in session storage, rate limits are explained, answers list their references, and thumbs feedback is sent to the existing endpoint |
| Overlays | EUI tooltips, toasts and flyouts | `Tooltip` needs no script. `Toast` and `Flyout` reveal their dismiss and open buttons from script. `Banner`, `Skeleton` and `EmptyState` are plain markup |
@@ -172,6 +172,8 @@ These replace React components built on EUI. Each renders complete markup on the
The server renders each of these without the legacy custom elements, so a flag-on page loads no EUI components.
+Every menu, in both layouts, is a `button[popovertarget]` that opens a `[popover]`. The browser draws it in the top layer and closes it on Escape and a click outside. `Assets/floating.ts` places it beside its button with Floating UI, flips and shifts it to stay on screen, and closes it on a page swap or after a link in it is chosen. `data-placement` picks the side, `data-anchor` names another anchor, and `data-hover` also opens the menu while a mouse rests on it. A menu rendered more than once on a page takes its id from its model.
+
## Layers
The design system declares its cascade layers under a `ds` namespace so they never merge with other stylesheets' layers. The order lives in `Assets/ds-layers.css`, which must load before `ds.css`:
@@ -210,7 +212,8 @@ To write your own theme, load a stylesheet after `ds.css` that overrides roles.
The design-system stylesheets target Chrome and Edge 111, Firefox 113 and Safari 16.2 or later.
The bundle sets this floor in the `ds-css` and `ds-guide-css` targets in `package.json`.
The floor is set by `color-mix()`, which has no fallback.
-`:has()`, container queries and popovers enhance the page where the browser has them and fall back to a simpler layout where it doesn't.
+`:has()` and container queries enhance the page where the browser has them and fall back to a simpler layout where it doesn't.
+Menus need the Popover API, which Safari has from version 17. Without it a menu stays closed, the link menu shows its links inline, and the applies-to panel shows while its badge has focus.
## Heroes, backgrounds and the call to action
diff --git a/src/Elastic.ApiExplorer/_Partials/Layout/_DesignSystemApiNav.cshtml b/src/Elastic.ApiExplorer/_Partials/Layout/_DesignSystemApiNav.cshtml
index f5eb975b58..2f34b03060 100644
--- a/src/Elastic.ApiExplorer/_Partials/Layout/_DesignSystemApiNav.cshtml
+++ b/src/Elastic.ApiExplorer/_Partials/Layout/_DesignSystemApiNav.cshtml
@@ -10,6 +10,7 @@
@await RenderPartialAsync(_LinkMenu.Create(new LinkMenuModel
{
+ Id = "api-version-menu",
Label = "API version",
Items = [.. apiContext.Versions.Select(item => new LinkMenuItem(item.Label, item.Value, item.Selected))]
}))
@@ -19,6 +20,7 @@
{
@await RenderPartialAsync(_LinkMenu.Create(new LinkMenuModel
{
+ Id = "api-product-menu",
Label = "API product",
Items = [.. apiContext.ProductGroups.SelectMany(group => group.Products).Select(item => new LinkMenuItem(item.Label, item.Url, item.Selected))]
}))
diff --git a/src/Elastic.Documentation.Site/Assets/ds.ts b/src/Elastic.Documentation.Site/Assets/ds.ts
index 0eb090957a..751fcbb851 100644
--- a/src/Elastic.Documentation.Site/Assets/ds.ts
+++ b/src/Elastic.Documentation.Site/Assets/ds.ts
@@ -4,6 +4,7 @@
import { bindApiBetaBanner } from './api-beta-banner'
import { initApiChromeSync } from './api-chrome-sync'
import { initApiColumnResize } from './api-column-resize'
+import { initAppliesPopovers } from './ds/applies-popover'
import { initAskAi } from './ds/ask-ai'
import { initCarousels } from './ds/carousel'
import { initCopyButtons, initCopyText } from './ds/copy'
@@ -12,12 +13,10 @@ import { initDocsBarSync } from './ds/docs-bar'
import { initFeedback } from './ds/feedback'
import { initLightboxes } from './ds/lightbox'
import { initListings } from './ds/listing'
-import { bindOutsideClick, initMenus } from './ds/menu'
import { initNav } from './ds/nav'
import { initNavFilter } from './ds/nav-filter'
import { initFlyoutResize, initFlyouts, initToasts } from './ds/overlays'
import { initPageJumpers } from './ds/page-jumper'
-import { initInlinePopovers, initPopovers } from './ds/popover'
import { initPreferences } from './ds/preferences'
import './ds/runtime'
import { bindSearchShortcut, initSearch } from './ds/search'
@@ -45,9 +44,7 @@ function init(scope: ParentNode = document) {
initTabSync(scope)
initCopyButtons(scope)
initCopyText(scope)
- initMenus(scope)
- initPopovers(scope)
- initInlinePopovers(scope)
+ initAppliesPopovers(scope)
initFeedback(scope)
initSearch(scope)
initSearchPage(scope)
@@ -69,7 +66,6 @@ function init(scope: ParentNode = document) {
void loadStorybookStories(scope)
}
-bindOutsideClick()
// The banner sits outside #main-container, so htmx:load does not reach a banner that navigation brings in.
bindApiBetaBanner((banner) => init(banner))
initDocsBarSync()
diff --git a/src/Elastic.Documentation.Site/Assets/ds/applies-popover.test.ts b/src/Elastic.Documentation.Site/Assets/ds/applies-popover.test.ts
new file mode 100644
index 0000000000..21ad654e9c
--- /dev/null
+++ b/src/Elastic.Documentation.Site/Assets/ds/applies-popover.test.ts
@@ -0,0 +1,93 @@
+import { initAppliesPopovers, unbindAppliesPopovers } from './applies-popover'
+
+const badge = `
+
+
+ Details
+`
+
+describe('applies-to popovers', () => {
+ const showPopover = HTMLElement.prototype.showPopover
+
+ beforeEach(() => {
+ // jsdom has no popover API; the module binds only where it exists.
+ HTMLElement.prototype.showPopover = vi.fn()
+ document.body.innerHTML = badge + badge
+ })
+
+ afterEach(() => {
+ HTMLElement.prototype.showPopover = showPopover
+ })
+
+ const triggers = () =>
+ Array.from(document.querySelectorAll('[data-applies-trigger]'))
+ const panels = () =>
+ Array.from(document.querySelectorAll('[data-applies-panel]'))
+
+ it('makes each button open its own panel as a popover', () => {
+ initAppliesPopovers()
+
+ const [first, second] = panels()
+ expect(first.getAttribute('popover')).toBe('')
+ expect(first.id).not.toBe(second.id)
+ triggers().forEach((trigger, i) =>
+ expect(trigger.getAttribute('popovertarget')).toBe(panels()[i].id)
+ )
+ })
+
+ it('gives badges brought in by a later swap ids of their own', () => {
+ initAppliesPopovers()
+ const before = panels().map((panel) => panel.id)
+
+ document.body.insertAdjacentHTML('beforeend', badge)
+ initAppliesPopovers()
+
+ const added = panels()[2]
+ expect(before).not.toContain(added.id)
+ expect(
+ panels()
+ .slice(0, 2)
+ .map((panel) => panel.id)
+ ).toEqual(before)
+ })
+
+ it('leaves the panel to show on focus where the browser has no popovers', () => {
+ HTMLElement.prototype.showPopover =
+ undefined as unknown as typeof showPopover
+
+ initAppliesPopovers()
+
+ expect(panels()[0].hasAttribute('popover')).toBe(false)
+ expect(
+ document
+ .querySelector('[data-applies-popover]')!
+ .hasAttribute('data-applies-bound')
+ ).toBe(false)
+ })
+
+ it('gives a cloned badge a panel of its own once it is unbound', () => {
+ document.body.innerHTML = badge
+ initAppliesPopovers()
+ const original = panels()[0]
+ triggers()[0].setAttribute('aria-expanded', 'true')
+ const copy = document.createElement('div')
+ copy.innerHTML = document.body.innerHTML
+
+ unbindAppliesPopovers(copy)
+ document.body.append(copy)
+ initAppliesPopovers(copy)
+
+ const copied = copy.querySelector('[data-applies-panel]')!
+ expect(copied.id).not.toBe(original.id)
+ expect(
+ copy
+ .querySelector('[data-applies-trigger]')!
+ .getAttribute('popovertarget')
+ ).toBe(copied.id)
+ expect(
+ copy
+ .querySelector('[data-applies-trigger]')!
+ .hasAttribute('aria-expanded')
+ ).toBe(false)
+ })
+})
diff --git a/src/Elastic.Documentation.Site/Assets/ds/applies-popover.ts b/src/Elastic.Documentation.Site/Assets/ds/applies-popover.ts
new file mode 100644
index 0000000000..7704c5ff77
--- /dev/null
+++ b/src/Elastic.Documentation.Site/Assets/ds/applies-popover.ts
@@ -0,0 +1,38 @@
+// The applies-to badge opens its panel as a popover: the browser opens and closes it, and floating.ts places it beside the button.
+// A page renders the badge many times, from Markdown, tables and API pages that share no counter, so the server cannot give each
+// panel a unique id. Binding gives it one and points the button at it. Unbound, the panel shows while the button has focus.
+// Hooks: [data-applies-popover] on the wrapper, [data-applies-trigger] on the button and [data-applies-panel] on the panel.
+let count = 0
+
+export function initAppliesPopovers(scope: ParentNode = document) {
+ if (typeof HTMLElement.prototype.showPopover !== 'function') return
+ scope
+ .querySelectorAll(
+ '[data-applies-popover]:not([data-applies-bound])'
+ )
+ .forEach((root) => {
+ const trigger = root.querySelector('[data-applies-trigger]')
+ const panel = root.querySelector('[data-applies-panel]')
+ if (!trigger || !panel) return
+ panel.id = `applies-popover-${++count}`
+ panel.setAttribute('popover', '')
+ trigger.setAttribute('popovertarget', panel.id)
+ root.dataset.appliesBound = ''
+ })
+}
+
+/** A cloned badge carries the original's panel id and `popovertarget`, so it would open the original panel. Unbind it, then `initAppliesPopovers` binds the copy. */
+export function unbindAppliesPopovers(scope: ParentNode) {
+ scope
+ .querySelectorAll('[data-applies-bound]')
+ .forEach((root) => {
+ const trigger = root.querySelector('[data-applies-trigger]')
+ const panel = root.querySelector('[data-applies-panel]')
+ panel?.removeAttribute('id')
+ panel?.removeAttribute('popover')
+ trigger?.removeAttribute('popovertarget')
+ // The copy's panel starts closed, whatever state the original was in.
+ trigger?.removeAttribute('aria-expanded')
+ delete root.dataset.appliesBound
+ })
+}
diff --git a/src/Elastic.Documentation.Site/Assets/ds/docs-bar.test.ts b/src/Elastic.Documentation.Site/Assets/ds/docs-bar.test.ts
index 4d1f4128a3..cc274f1dcb 100644
--- a/src/Elastic.Documentation.Site/Assets/ds/docs-bar.test.ts
+++ b/src/Elastic.Documentation.Site/Assets/ds/docs-bar.test.ts
@@ -1,7 +1,7 @@
import { syncDocsBar } from './docs-bar'
const bar = (current: string) =>
- ``
+ ``
describe('docs bar sync', () => {
beforeEach(() => {
@@ -20,14 +20,6 @@ describe('docs bar sync', () => {
expect(document.querySelectorAll('#docs-bar')).toHaveLength(1)
})
- it('binds the menus of the new bar', () => {
- syncDocsBar(`${bar('b')}`)
-
- expect(
- document.querySelector('details')?.hasAttribute('data-menu-bound')
- ).toBe(true)
- })
-
it('binds the theme switch of the new bar so its choices apply', () => {
const withSwitch = ``
document.documentElement.removeAttribute('data-theme')
@@ -43,19 +35,6 @@ describe('docs bar sync', () => {
expect(document.documentElement.dataset.theme).toBe('dark')
})
- it('binds the popovers of the new bar so its menu is shown in the top layer', () => {
- HTMLElement.prototype.showPopover = function () {}
- HTMLElement.prototype.hidePopover = function () {}
- const withMenu = ``
- syncDocsBar(`${withMenu}`)
-
- expect(
- document
- .querySelector('[data-popover-panel]')
- ?.getAttribute('popover')
- ).toBe('manual')
- })
-
it('leaves the bar alone when the response has none', () => {
const changed = syncDocsBar('
a search result
')
diff --git a/src/Elastic.Documentation.Site/Assets/ds/docs-bar.ts b/src/Elastic.Documentation.Site/Assets/ds/docs-bar.ts
index 2bb99a61fb..7b8492def7 100644
--- a/src/Elastic.Documentation.Site/Assets/ds/docs-bar.ts
+++ b/src/Elastic.Documentation.Site/Assets/ds/docs-bar.ts
@@ -1,5 +1,3 @@
-import { initMenus } from './menu'
-import { initPopovers } from './popover'
import { initPreferences } from './preferences'
// htmx swaps #main-container and the docs bar sits above it, so after a boosted navigation the bar would keep the previous page's
@@ -13,9 +11,8 @@ export function syncDocsBar(html: string): boolean {
// A partial response, such as a search result, has no bar and leaves ours alone.
if (!next) return false
current.replaceWith(next)
- // The htmx:load initializers only scan the swapped container, so the new bar's menus, their top-layer popovers and its theme switch are bound here.
- initMenus(next)
- initPopovers(next)
+ // The htmx:load initializers only scan the swapped container, so the new bar's theme switch is bound here. Its menus are popovers
+ // that need no binding.
initPreferences(next)
return true
}
diff --git a/src/Elastic.Documentation.Site/Assets/ds/menu.test.ts b/src/Elastic.Documentation.Site/Assets/ds/menu.test.ts
deleted file mode 100644
index 1bf3358bb7..0000000000
--- a/src/Elastic.Documentation.Site/Assets/ds/menu.test.ts
+++ /dev/null
@@ -1,89 +0,0 @@
-import { bindOutsideClick, initMenus } from './menu'
-
-const menu = `
-Version