Skip to content

Keep the API Copy page menu on screen on phones - #4965

Merged
reakaleek merged 9 commits into
mainfrom
floating-ui-refactor-ca03c92b
Nov 19, 2026
Merged

reakaleek merged 9 commits into
mainfrom
floating-ui-refactor-ca03c92b

Conversation

@reakaleek

@reakaleek reakaleek commented Nov 19, 2026 •

Copy link
Copy Markdown
Member

The API Copy page menu now opens beside its chevron and stays inside the viewport on a phone. A new Floating UI controller, floating.ts, places it and the other API menus.

Affects: API reference, Site UI

Prompt summary: The Copy page dropdown mispositions itself in mobile view. The goal is one Floating UI based way to place everything that floats in the UI, replacing the duplicate implementations. This PR is the first slice: the controller and the API menus.

Why

The Copy page menu was an absolutely positioned <details> panel with right: 0. On a phone it ran off the screen edge, and nothing flipped or shifted it. It also sat in a z-index: 6 stacking context, so later siblings could cover it. The frontend places floating elements four different ways, and two hand-rolled copies of the same placement math sit beside the one Floating UI user.

What

One placement controller

floating.ts turns any [popover] opened by a [popovertarget] button into a menu that Floating UI places and follows. data-placement picks the side and data-anchor names a different anchor. It releases tracking when the menu closes or an htmx swap removes it, and it replaces api-menu.ts.

Menus moved onto it

Copy page, the spec download, the API hub menu and the "+N more" chip menus are popovers. The top layer stops ancestors from clipping them, and the browser handles click outside and Escape. The filtered union menu anchors to its search box.

Code removed

The hand-rolled positionMenu and its scroll listeners in chip-row.ts, api-menu.ts, and an unused copy of the page-actions CSS in api-reference.css.

Out of scope: the top-bar, design-system and tooltip surfaces still use their old code. They follow in separate PRs.

Verify

mise run site:test
dotnet test --project tests/Elastic.ApiExplorer.Tests
mise run serve   # open /api/cloud-connect at 375px and open Copy page

The first API page request after mise run serve takes about two minutes while the spec loads.

Check on the preview

  • Cloud Connect API — at a phone width, open Copy page. The menu sits under the chevron and stays on screen.
  • Cloud Connect API — control: at desktop width the API and version menu in the sidebar still opens and closes.

… screen

The Copy page menu was an absolutely positioned details panel. On a phone it
ran off the right edge, and nothing flipped or shifted it. Copy page, the spec
download, the API hub menu and the "more" chip menus are now popovers that
floating.ts places beside their button. The popover draws in the top layer, so
no ancestor can clip it, and the browser handles click outside and Escape.

This deletes the hand-rolled positionMenu in chip-row.ts, the api-menu.ts
module that floating.ts generalises, and an unused copy of the page-actions CSS.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
@reakaleek
reakaleek requested a review from a team as a code owner November 19, 2026 20:19
@reakaleek
reakaleek requested a review from akira28 November 19, 2026 20:19
@reakaleek reakaleek added the bug label Nov 19, 2026
reakaleek and others added 2 commits November 19, 2026 21:21
…ca03c92b

# Conflicts:
#	tests/Elastic.ApiExplorer.Tests/.snapshots/PageActionsRenderingTests/Render_SplitButton_CopiesPageAndOpensMarkdown.verified.html
#	tests/Elastic.ApiExplorer.Tests/.snapshots/PageActionsRenderingTests/Render_WithSpec_ListsJsonAndYamlDownloads.verified.html
#	tests/Elastic.ApiExplorer.Tests/.snapshots/PageActionsRenderingTests/Render_WithoutMarkdown_OffersTheDownloadsAlone.verified.html
#	tests/Elastic.ApiExplorer.Tests/.snapshots/PageActionsRenderingTests/Render_WithoutSpec_HasNoDownloads.verified.html
Main now serves API pages at /docs/api/<key>. The four page-actions
snapshots keep the popover markup and take the new URLs, and the Copy page
journey opens the new path.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
Comment on lines +13 to +16
click ".api-page-actions-chevron"
expect visible "#api-page-actions-menu"
expect attr ".api-page-actions-chevron" aria-expanded true
expect visible find role menuitem --name "View as Markdown"

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-level bounds assertion for the mobile placement fix. This journey passes if the menu opens partly off-screen or centered far from the chevron, and the unit tests stub the positioning result. Check that the open menu is fully inside the 375px viewport and aligned with its trigger.

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.

Partly addressed in f03e04c. The journey language cannot assert a box, and its get box only writes a transcript, which a deployed-site run does not compare. So the journey keeps to open and close, and the header says so. The bounds check is now floating-placement.test.ts: the real Floating UI middleware against a 375px viewport, with Copy page's chevron at the right edge and a 273px menu. It asserts the menu stays 8px inside the screen, sits under the chevron and does not pass its right edge. A second case checks it flips above near the bottom. Removing shift fails the first and removing flip fails the second. The geometry is stubbed, so I also measured the real page in Chrome at 375, 768 and 1280px; all three stay on screen.

reakaleek and others added 4 commits November 19, 2026 21:27
…ew by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…(per review by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…r review by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…h (per review by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
reakaleek and others added 2 commits November 19, 2026 21:34
…(per review by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
…ed (per review by @infra-vault-gh-plugin-prod)

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
.api-page-actions-dropdown.is-open .api-page-actions-chevron-icon {
transform: rotate(180deg);
/* Without the Popover API (floating.css hides the menu) the download-only page has nothing else on it, so its links show inline in place of the button. */
@supports not selector(:popover-open) {

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)

The updated snapshot verifies the modifier class, but it cannot catch a CSS regression that hides both download links when popovers are unsupported. Add a browser-level check for the download-only fallback that verifies the trigger is hidden and both links remain visible.

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 new test, but I ran the check you describe against the shipped CSS in Chrome. I took every rule from the built @supports not selector(:popover-open) blocks, including floating.css's [popover] { display: none }, and applied them unwrapped to a page whose menu keeps its popover attribute, so the two rules compete as they would in a browser without the API. On a download-only page the trigger is hidden and both download links are visible at 375px. On the Copy page variant the menu stays hidden. The fallback wins on specificity, since both stylesheets are unlayered. I did not add this to the repo because neither harness can turn the Popover API off. The journey language has no way to do it, and the visual suite only compares screenshots. A test would have to unwrap the rules itself, so it would re-check my emulation, not the browser. For a path only browsers older than 2024 reach, I think that is not worth a new test setup. Say so if you want one anyway.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I don’t think a bespoke test setup is warranted for this low-severity fallback. Your check is useful evidence that the current rules produce the intended result: the download-only split control is hidden while its menu is displayed under the @supports not selector(:popover-open) fallback (api-docs.css), alongside the rule that hides [popover] elements without the API (floating.css). It isn’t durable regression coverage or a run in an unsupported browser, but given the harness limitation and the age-limited path, I wouldn’t ask you to add a custom emulation test.

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

@github-actions

Copy link
Copy Markdown
Contributor

@reakaleek
reakaleek merged commit b062c65 into main Nov 19, 2026
44 checks passed
@reakaleek
reakaleek deleted the floating-ui-refactor-ca03c92b branch November 19, 2026 20:54
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