Skip to content

Open every menu as a popover placed by Floating UI - #4968

Merged
reakaleek merged 25 commits into
mainfrom
floating-menus-everywhere
Nov 19, 2026
Merged

reakaleek merged 25 commits into
mainfrom
floating-menus-everywhere

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

Every remaining menu and popover in the site chrome now opens as a [popover] that floating.ts places, and the code each one carried for placing and dismissing itself is deleted. The branch removes about 800 more lines than it adds.

Affects: Site UI, Navigation

Prompt summary: Everything that floats in the docs UI should be placed by Floating UI through one shared implementation, and the duplicate implementations should go. PR #4965 added the controller and moved the API menus. This PR moves the rest of the menus onto it.

Why

After #4965 the legacy sidebar menu and the design-system menus still had their own placing code. ds/popover.ts and ds/menu.ts positioned panels by hand, the theme switch used a checkbox hack, and each menu closed itself in its own way. A menu inside a scrolling container could be clipped, and none of them flipped or shifted near an edge.

What

Menus on the one primitive

The design-system DocsBar, LinkMenu, DeploymentInfo, theme switch, split button, applies-to badge (block and inline) and page jumper results, and the legacy #pages-dropdown, open as popovers beside their trigger. Escape, outside click and the htmx swap close them. The legacy dropdown's link and chevron are now two controls, where a link used to sit inside a button.

Hover and link close in floating.ts

data-hover opens a menu while a mouse rests on its button or on the menu, closes it 150ms after the mouse leaves, and keeps it open if the button is then clicked. Choosing a link closes its menu, so downloads and new-tab links no longer leave one open.

Code deleted

ds/popover.ts, the dismissal in ds/menu.ts and ds/preferences.ts, the open and close code in secondary-nav.ts (it keeps the active-tab sync), the unused _NavSelect partial, and the top-bar section dropdown. That dropdown cannot render: it needs NAVIGATION_PREVIEW, and with that flag on every layout uses the design-system header instead.

Tradeoffs: in a browser without the Popover API (Safari before 17), the DocsBar dropdowns, theme menu, DeploymentInfo, split button and #pages-dropdown stay closed. LinkMenu shows its links inline, and the applies-to panel opens on focus. The docs say so.

Not verified: the assembler visual comparison, the API version switcher (no local API has two versions), and Escape on a page with the elastic.co header, which unit tests cover. visual:seed times out on two pages on main itself, so the isolated baseline was seeded by hand and is identical on this branch.

Verify

mise run site:test
mise run test
mise run journeys:test
mise run serve   # open /syntax/images, the style guide's menu examples, and a page's sidebar section menu

Check on the preview

  • Docs home — open the section and version menus at phone width: each sits beside its button and stays on screen.
  • Images — control: closed menus look the same as before.

reakaleek and others added 9 commits November 19, 2026 21:57
Nothing renders `_NavSelect.cshtml` or builds `NavigationSelectModel`. The
`.nav-select-dropdown`, `.nav-select-menu` and `.nav-select-option` rules only
styled that partial. The React `VersionDropdown` keeps the `.nav-select`
trigger rules it uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`_SecondaryNav.cshtml` renders its section dropdown only when
`NAVIGATION_PREVIEW` is on. With the flag on, every layout renders the
design-system header instead of `_AssemblerHeader`, and the page loads
`ds.js`, not `main.js`. So no page shows the dropdown, and its close-on-
outside-click, Escape and motion code in `secondary-nav.ts` never runs.

This removes the dropdown branch, its motion and overflow CSS, and that
code. `secondary-nav.ts` keeps the active-tab sync, and
`secondary-nav-dropdown.css` keeps the link rows the API hub menu uses.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A popover marked `data-hover` opens while a mouse rests on its button or
on the menu, and closes 150ms after the mouse leaves both. Touch and
keyboard still use the click. The design-system deployment info needs
this to leave its `details` element.

Choosing a link now closes the menu it is in. A boosted link already
closed it through the htmx swap, but a download or a new-tab link left
it open.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The legacy sidebar's section menu opened while its box had focus. It
hung below the box with `position: absolute` and put a link inside a
button. The link and the chevron are now separate controls: the
chevron opens a popover that `floating.ts` places under the whole box.
Escape, outside click and htmx navigation close it. The mousedown and
mouseup focus workaround in `pages-nav.ts` goes with the focus trick.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The results panel hung under the field with `position: absolute`, so
an ancestor's overflow could clip it. It is now a manual popover that
`floating.ts` places under the field through `data-anchor`, as wide as
the field. Focus stays in the field while the reader types, so the
script keeps closing the panel on Escape and on a click outside the
form. Without the Popover API the field stays a plain search form.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The docs bar dropdowns, link menus, deployment info, theme menu, split
button and applies-to badge were `details` elements or a checkbox. Each
hung its panel below with `position: absolute`, and `ds/menu.ts`,
`ds/popover.ts` and `ds/preferences.ts` each closed them in their own
way. They are now buttons that open popovers. The browser closes them
on Escape and a click outside, and `floating.ts` places them and keeps
them on screen.

- `LinkMenuModel` and the components that can appear more than once
  take an id, so each button opens its own menu.
- The deployment info opens on mouse hover through `data-hover`.
- The applies-to badge renders on many unrelated paths with no shared
  counter, so `ds/applies-popover.ts` gives each panel its id at bind
  time. Unbound, the panel still shows while its badge has focus.
- Without the Popover API the link menu shows its links inline.

`ds/menu.ts` and `ds/popover.ts` are deleted, and so are the theme
switch's checkbox and its dismissal code. The docs bar snapshots also
pick up the deprecated badge in the search result template, which
changed in #4668.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The style guide's decisions and `design-system.md` still said menus
were `details` elements. They now describe the popover button that
every menu uses, what `floating.ts` adds, and what a browser without
the Popover API shows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A mouse that rests on a `data-hover` button opens its menu, and the
click that usually follows toggled it shut again. The click now keeps
the menu open, and the menu then stays open after the mouse leaves,
until Escape or a click outside closes it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 19, 2026 22:08
@reakaleek
reakaleek requested a review from akira28 November 19, 2026 22:08
Comment on lines +14 to +22
<button type="button" class="docs-bar__link" popovertarget="@menuId" aria-haspopup="menu" aria-expanded="false">
@if (item.Icon is { } dropdownIcon)
{
@await RenderPartialAsync(_Icon.Create(new IconModel { Name = dropdownIcon, Size = IconSize.Small }))
}
<span>@item.Title</span>
@await RenderPartialAsync(_Icon.Create(new IconModel { Name = "chevron_single_down", Size = IconSize.Small }))
</button>
<div id="@menuId" class="docs-bar__menu" aria-label="@item.Title" popover>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P2 (Medium)

Keep the DocsBar navigation links reachable without the Popover API. On browsers within the documented stylesheet floor, such as Safari 16.2 and Firefox 113, the new button does nothing and the global popover rule hides every link in the dropdown. The previous disclosure worked on those browsers; the legacy section picker now loses its links in the same way.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No change. This is the tradeoff the PR description and docs/development/design-system.md state: without the Popover API (Safari before 17, Firefox before 125) the DocsBar dropdowns and the legacy section picker stay closed, while LinkMenu and the applies-to panel keep a fallback. A no-popover layout for the DocsBar would need its own inline menu inside a tab list that scrolls sideways, which is the clipping this PR removes, for browsers that are a small share of traffic. If the support floor for the stylesheet is meant to include them, say so and I will add a @supports not selector(:popover-open) fallback in a follow-up.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Yes—the documented target floor includes Firefox 113 and Safari 16.2: the design-system support statement says so, and Vite’s CSS target confirms it. The same documentation explicitly notes the exception that menus require the Popover API and stay closed without it. So the support floor itself isn’t ambiguous; this is a documented usability tradeoff for those menus. The new DocsBar markup uses a native popover and popovertarget (lines 14–22).

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

reakaleek and others added 5 commits November 19, 2026 23:16
The version switcher is a LinkMenu button now, so the navigation-preview branch waited for a `summary` that no longer exists. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The copy kept the original badge's panel id and popovertarget, so clicking it in the dialog opened the panel behind the dialog. Unbind the clone and bind it again once it is in the page. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Neither collection ever dropped its menu keys, so menus an htmx swap detached stayed in memory for the page session. A WeakMap and a WeakSet release them with the element. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
pointerover fires between the children of the button, so a click that closed a hover menu was undone by the next small mouse move. Skip the open when the pointer comes from the button or the menu. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
A middle click opens the link in a new tab through auxclick, which the click listener never saw, so the menu stayed open on the original page. Addresses Libra review feedback on #4968.

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

Copy link
Copy Markdown
Contributor

reakaleek and others added 2 commits November 19, 2026 23:18
The LinkMenu, DocsBar dropdowns and the legacy section picker open a plain list of links with no menu roles or arrow-key behaviour, so announcing a menu misled screen readers. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Without the Popover API or script the panel shows only while the badge button has focus, and Safari does not focus a button on click. An explicit tabindex makes a mouse click open the panel there. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
reakaleek and others added 2 commits November 19, 2026 23:24
A badge copied into the fullscreen table while open kept aria-expanded="true" although its panel starts closed. Unbinding now sets it back to false. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Removing an open popover fires no toggle, so a badge left open in the dialog kept Floating UI tracking a detached element until the next page swap. floating.ts now exports closePopoversWithin and the dialog calls it before removing itself. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
reakaleek and others added 2 commits November 19, 2026 23:37
…968-6c895be5

# Conflicts:
#	src/Elastic.Documentation.Site/Assets/floating.ts
closePopoversWithin skipped any tracked popover that was no longer in the page, so closeAll stopped releasing the ones a code path had removed while open. Removed popovers are now released whatever the root. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
var html = await _TocTree.Create(model).RenderAsync(cancellationToken: TestContext.Current!.Execution.CancellationToken);

html.Should().MatchHtmlSnapshot(DocsHtml.Body().Select("#nav-dropdown"));
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P3 (Low)

Add a browser journey for the flag-off section picker. This snapshot verifies the markup but would pass if the legacy bundle never placed the popover or if selecting a section failed to navigate. The updated journeys exercise the design-system link menus or the separate legacy version picker, not this control.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Valid gap, tracked as #4969. The picker only renders on the assembler site with navigation-preview off. The isolated docs/ site never shows it, and prod and edge still run the old markup, so a journey written now could not be run against this change. The issue describes the journey to add once the branch is on edge. Not blocking this PR.

reakaleek and others added 2 commits November 19, 2026 23:47
A timer started by leaving the button still ran after Escape closed the menu, so reopening it from the focused button within 150ms closed it again. The toggle handler now clears the timer. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Their panels are plain text and links with no menu roles or arrow-key behaviour, so announcing a menu misled screen readers. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
The panel is a plain popover of radio groups with no dialog role or name, so announcing a dialog promised semantics it does not have. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
reakaleek and others added 2 commits November 19, 2026 23:59
A static aria-expanded="false" overrides the state the browser reports for a popovertarget button, so without script an open menu was announced as collapsed. The markup no longer carries it, and floating.ts sets it from the first toggle on. Addresses Libra review feedback on #4968.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The panel is a plain popover with no dialog role or name, the same case as the theme switch cog. Follows the Libra review feedback on #4968.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
if (!(popover instanceof HTMLElement) || !popover.hasAttribute(FLOATING))
return
const open = (event as ToggleEvent).newState === 'open'
// The markup carries no `aria-expanded`, so without script the browser reports the button's own state.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Severity: P3 (Low)

Add a browser regression check for the native expanded state with the Floating UI script disabled. The version-picker journey reads aria-expanded only after this handler writes it, and the HTML snapshots cannot check what assistive technology receives. Neither test verifies that the button is exposed as collapsed before activation and expanded afterward without the script.

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

@reakaleek
reakaleek merged commit e7e2367 into main Nov 19, 2026
44 checks passed
@reakaleek
reakaleek deleted the floating-menus-everywhere branch November 19, 2026 23:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant