Skip to content

ui-kit: anchored menus and pickers hand-roll dismissal and clip instead of using native popovers #2583

Open

Description

@schlessera

Context

Part of #2576. Easier after #2578, which settles the roles; it does not wait on it.

Five anchored menus and pickers are hand-rolled: an absolutely positioned div at z-popover, plus document mousedown/pointerdown and keydown listeners for dismissal:

Surface Code
Share menu (ShareMenu, packages/ui-react/src/components/share/share-menu.tsx:53-72) listeners, :124-143 panel
Provider picker + desktop Attach (Composer, packages/ui-react/src/components/chat/composer.tsx:332-352) shared listeners gated on matchMedia("(min-width: 900px)"). Panels at packages/ui-react/src/components/chat/composer-view.tsx:191-204
Model picker (desktop) (ModelPicker, packages/ui-kit/src/chrome/ModelPicker.tsx:59-67) Escape and a hand-written Tab wrap, :157-160 the positioned box
Session row overflow (SessionOverflow, packages/ui-react/src/components/chat/session-list.tsx:311-352)
Pending follow-up reveal (PendingFollowUps, packages/ui-kit/src/chrome/PendingFollowUps.tsx:132-144) outside-tap listener, :255-295 hover/focus/tap reveal

Costs today:

  • About 70 lines of listener code.
  • No Android back dismissal.
  • The panels are clipped by any ancestor that contains paint. (.chat-message-body, packages/ui-react/src/theme.css:651-667) had to narrow content-visibility: auto to the message body because "the share dropdown opens past the bottom of its message".

popover="auto" gives light dismiss, Escape and close-request (Android back) dismissal, and top-layer rendering with no clipping. CSS anchor positioning places the panel without measuring. Support: popover Chrome Android 114, Samsung 23, Firefox Android 125. anchor-name 125/27/147. position-try-fallbacks 128/28/147.

Guide ui-atoms/viewport-aware-dropdowns and ui-behaviors/declarative-dialog-popover-control. The guides' polyfills are not allowed under the epic's policy.

Recorded decision — 2026-10-22

The maintainer ruling approves auto top-layer popovers for Share, Provider picker, desktop Attach, desktop ModelPicker and Session overflow, amending D54’s panel/popover order. ModelPicker has no Tab trap: Tab out closes it and focus continues forward. PendingFollowUps is a manual top-layer popover driven by existing hover/focus/tap handlers, with one retained outside-tap listener and explicit Escape/close-request handling. Unsupported anchor positioning uses the accepted bottom-docked geometry at every width, full width up to max width, centred above the safe area. All four choices are settled.

Scope

Implement the accepted branch:

  • Each surface except PendingFollowUps renders popover="auto", opened with showPopover()/togglePopover() from its trigger. Its toggle event keeps React state in sync, so light dismiss, Escape and Android back all update open. Remove the matching document dismissal listeners. PendingFollowUps uses popover="manual", retains its one outside-tap listener and adds Escape/close-request dismissal. ModelPicker removes the Tab wrap; focus-out closes it without trapping or stealing the next focus target.
  • Position with CSS anchor positioning. Derive each anchor name from useId() so instances never collide, and use position-try-fallbacks: flip-block. Under @supports not (anchor-name: --a), use the ruled fallback geometry. No polyfill.
  • Feature-detect popover with "popover" in HTMLElement.prototype. Where it is missing (none of the current targets), keep today's positioned div and listeners.
  • After Share moves to the top layer, widen content-visibility: auto in theme.css:651-667 to the whole message, as its comment anticipates, and update that comment.
  • Amend the D54 layer table and the @layers block in overlays.md in the same PR.

Out of scope

Acceptance criteria

  • The maintainer has ruled on all four choices.
  • Record the accepted layer/fallback/manual-popover amendment in overlays.md and its @layers block.
  • If yes: every surface in the table opens in the top layer. Each closes on outside tap, on Escape and on a close request, with open state in sync and focus returned to its trigger. All automatic surfaces remove document dismissal listeners. PendingFollowUps alone retains its one outside-tap listener and explicit close-request handling. Tests cover its outside tap, Escape and Android Back. ModelPicker Tab-out closes it and continues focus forward.
  • If yes: a real-Chromium test opens Share inside a long message and inside an open Files panel, and asserts that the panel is fully visible and above the Files panel. It fails on the current tree. A second run forces the @supports not (anchor-name) path through an injected stylesheet override and asserts the fallback geometry.
  • If yes: content-visibility is widened, and a long-transcript layout test shows no clipping of Share.
  • Visual baselines change only where the ruling approves.

Verification

bun run test packages/ui-kit packages/ui-react
node scripts/visual.mjs --project=visual --project=subjects
node scripts/visual.mjs --project=ui-react-layout
node scripts/visual.mjs --project=rail-fine --project=rail-coarse
bun run typecheck
bun run lint
bun run check:pr --base origin/main

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit.
  • This changes a published package's behaviour, so it needs a changeset.

ModelPicker and PendingFollowUps props stay as they are. LAYERS.popover and z.popover are present in api-report/ui-kit.txt and therefore supported exports. Use the maintainer-approved deprecation path: preserve those exports and their existing values/CSS variable while internal users move to the top layer; document their deprecated status. Removing them is outside this scoped migration and needs its own prior breaking ruling, contract handling and migration. Do not retire --bk-z-popover while the supported z.popover export still refers to it.

2026-10-22 readiness reconciliation at inspected main aa8c896: folded the later maintainer ruling into the active specification and criteria. Earlier proposal/needs statements above describe their dated review stage. The accepted brief has no remaining needs prerequisite; add agent-ready. No implementation or runtime completion is claimed.

Activity

  1. added
    type: refactorStructure changes; behaviour does not. No changeset-visible effect.
    area: ui-reactReact chat/files/voice components, stores, WebSocket transport.
    area: ui-kitThe presentational design kit: components, tokens, Storybook, visual baselines.
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    on Oct 22, 2026
  2. schlessera commented on Oct 22, 2026

    @schlessera
    OwnerAuthor

    Maintainer ruling

    1. Yes: anchored menus and pickers move to the top layer with popover="auto". This covers Share, Provider picker, desktop Attach, ModelPicker and Session row overflow.
      • The D54 layer table is amended. Anchored popovers now render above panels and the connection banner, not at z-popover 20 under z-panel 40.
      • --bk-z-popover is retired if nothing else uses it.
      • Before merge, reassess the z.popover / LAYERS.popover export (tokens.ts:1319). If removing it is a supported-API removal, it needs contract and breaking handling. Otherwise, deprecate it first and remove it later.
    2. Desktop ModelPicker becomes <div role="dialog" popover="auto">. It light-dismisses and has no focus trap. The hand-written Tab wrap is removed. Tabbing out of the picker closes it (light dismiss on focus-out), and focus continues to the next control.
    3. PendingFollowUps becomes popover="manual", shown and hidden with showPopover()/hidePopover() from the existing hover, focus and tap handlers. It renders in the top layer with no clipping, and hovering never light-dismisses it.
      • Exception to the acceptance criteria: this surface keeps its one outside-tap listener for dismissal, because a manual popover has none natively. Add a close-request handler so Android back hides it too.
      • All other surfaces register no document mousedown, pointerdown or keydown listeners.
    4. Fallback where anchor-name is unsupported (@supports not (anchor-name: --a)): the popover docks to the bottom of the viewport, full width up to the popover's max width and centred, above env(safe-area-inset-bottom). This geometry is accepted at every width, including desktop, where it appears away from its trigger.

    overlays.md amendment (D54 layer table row)

    | Anchored popover vs a panel | Popover | Top layer (popover="auto"), above panels and the connection banner. Positioned with CSS anchor positioning and position-try-fallbacks: flip-block. Without anchor-name, docked to the viewport bottom above the safe area. PendingFollowUps is popover="manual". The desktop dictation popover stays in flow (it must not light-dismiss while draining). |

    Also update the @layers block in the same PR. Closing stays instant (D54). No new motion.

    Acceptance criteria adjustments

    • Exception: PendingFollowUps keeps one outside-tap listener and adds close-request handling. A test asserts that outside tap, Escape and Android back each hide it.
    • New: a ModelPicker test asserts there is no Tab trap, and that Tab out of the picker closes it and moves focus forward.
    • Unchanged: Share is fully visible inside a long message and above an open Files panel. The forced @supports not (anchor-name) run asserts the bottom-dock geometry. content-visibility is widened to the whole message.
  3. added
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    and removed
    needs: decisionBlocked on a maintainer or designer ruling, not on code.
    on Oct 22, 2026
  4. schlessera commented on Oct 22, 2026

    @schlessera
    OwnerAuthor

    2026-10-22 readiness reconciliation: folded the maintainer ruling into the body, replacing the unresolved-choice specification and aligning scope/criteria with the accepted branch. The remaining work is explicitly scoped; add agent-ready. Preserve priority, native parent, assignment and release attribution. This is issue preparation, not implementation, runtime proof or delivery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: ui-kitThe presentational design kit: components, tokens, Storybook, visual baselines.area: ui-reactReact chat/files/voice components, stores, WebSocket transport.priority: p2Wanted, not scheduled. Pulled in when a milestone has room.type: refactorStructure changes; behaviour does not. No changeset-visible effect.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions