Skip to content

[all components] Hide the focus ring when returning focus after a pointer close - #6351

Draft
jjenzz wants to merge 3 commits into
mui:masterfrom
jjenzz:codex/base-ui-issue-3dc5aa35-113c-47b8-a126-68605fa2c6bc
Draft

jjenzz wants to merge 3 commits into
mui:masterfrom
jjenzz:codex/base-ui-issue-3dc5aa35-113c-47b8-a126-68605fa2c6bc

Conversation

@jjenzz

@jjenzz jjenzz commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Fixes #6348

  • Cause: When a Combobox or Menu popup closes after a mouse, touch or pen pick, focus goes back to the trigger without saying whether a ring should show. Item presses keep focus in the popup, so if a key was pressed there first (typing in the input, Menu typeahead), Chrome still treats input as keyboard and shows the focus ring on the trigger.
  • Fix and rationale: FloatingFocusManager already passes focusVisible true when a popup closes from the keyboard. It now also passes focusVisible false when the close came from a mouse, touch or pen press, so the ring no longer depends on an earlier key press. Keyboard closes keep the ring, and closes with no known interaction type still leave the choice to the browser. Browsers older than Chrome 145 or Safari 18.4 ignore the option and keep the current behavior.
  • Considered: Blur the element focused inside the popup before returning focus. — In real Chrome 158 the trigger still showed the ring for both the Combobox and Menu cases, because Chrome keeps the earlier keyboard input state.
  • Considered: Stop preventing default on item presses so the press moves focus. — It breaks the Combobox rule that the input keeps focus while picking, and the Menu typeahead case still showed the ring.
  • Considered: Give each component its own finalFocus default. — It repeats one rule across many components, and an explicit finalFocus turns off the existing check for focus that already moved elsewhere.
  • Verification: Chromium, jsdom, ESLint, TypeScript, formatting. Regression fails before and passes after the fix.
BEFORE AFTER
before.mp4
after.mp4

@jjenzz jjenzz added component: combobox Changes related to the combobox component. type: bug It doesn't behave as expected. labels Nov 25, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

commit: 17858be

@code-infra-dashboard

code-infra-dashboard Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+33B(+0.01%) 🔺+10B(+0.01%)

Details of bundle changes

Performance

No regressions in 36 benchmarks · precise to ±10.9% (±20.4% at worst) · ran 3m 43s · details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 17858be
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6b070c9cec839188ff32afb5
😎 Deploy Preview https://deploy-preview-6351--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@jjenzz jjenzz added the scope: all components Widespread work has an impact on almost all components. label Nov 25, 2026
@jjenzz

This comment has been minimized.

@jjenzz

jjenzz commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

PR review

The fix is sound for normal use. When a popup closes by pointer and the return target isn't a text field, it now passes focusVisible: false. Return to text inputs still uses the browser's default. All five earlier review items are fixed in the current code, and I found no regression in keyboard, assistive-technology virtual-click or programmatic closes. The remaining gaps are small: one test name doesn't match what the test checks, and the text-input guard covers more input types than it needs to. I used read-only tools only and ran nothing; CI is the runtime proof.

Bugs (1)

1. ℹ️ The text-input exception also matches non-text <input> types

Location: packages/react/src/utils/popups/focus/FloatingFocusManager.tsx:953

} else if (closeType !== '' && !isTypeableElement(tabbableReturnElement)) {

isTypeableElement uses TYPEABLE_SELECTOR (input:not([type='hidden']):not([disabled]),…). That selector matches every visible input type, including checkbox, radio, button and range. Only text-entry inputs always show :focus-visible. Other input types follow the same heuristic as buttons: they inherit the focus-visible state of the element that last had focus.

Failure scenario: Base UI's own Slider.Thumb renders a nested <input type="range">. A popup is opened while that input is focused, or finalFocus points at it (or at a native checkbox, or the trigger is an <input type="button">). The user types in a text input inside the popup, then picks an item with the mouse; items prevent default, so focus does not move during the press. On close, focus returns to the range/checkbox/button input with { preventScroll: true } and no focusVisible: false, and the ring shows: the bug this PR fixes for buttons. This is rare, so it's a note.

Fix (optional): Narrow the exception to text-entry targets, for example with a check like isTypeableCombobox's text-input test, or by excluding non-text input types. Otherwise, mention the limit in the source comment.

Tests (1)

1. 🟡 The new text-input test promises a focus-ring outcome but only checks call arguments

Location: packages/react/src/utils/popups/focus/FloatingFocusManager.test.tsx ("lets a text input keep its focus ring when returning focus after pointer close")

await waitFor(() => {
  expect(focusSpy).toHaveBeenCalledWith({ preventScroll: true });
});

The title promises that the input keeps its focus ring. The test runs in jsdom, which has no :focus-visible, and only checks the arguments passed to focus(). It does catch removal of the guard, as the earlier mutation check showed. But it would still pass if a later change broke the focus ring by another route, and it would fail on a harmless refactor of the focus options.

Failure scenario: A test-audit junk pattern: the name promises behavior the assertions never exercise. The only behavioral proof of the text-input exception is a manual Chromium check from the earlier review round.

Fix: Pick one of these:

  • Rename it to what it checks, e.g. "does not pass focusVisible: false when returning focus to a text input after pointer close".
  • Make it it.skipIf(isJSDOM) and assert input.matches(':focus-visible') is true after a pointer close, mirroring the new ComboboxPopup test.

Test audit

I read all nine bundle files with Kody search: BASE-UI.md, SKILL.md, CAMPAIGN.md, references/audit.md, openclaw-testing.md, references/package-and-docker.md, writing-tests.md, boundary-scenarios.md and fixtures.md. I applied them as BASE-UI.md says: a focused PR audit, with Base UI tooling instead of OpenClaw's. CAMPAIGN.md and the package/Docker, fixture and OpenClaw CI guidance don't apply here.

Each changed test was given a ledger mark: R = retain, F = keep the test but repair it.

  • R – ComboboxPopup.test.tsx, "does not show the focus ring on the trigger after typing and then picking an item with a pointer" (Chromium only). This is the main behavioral test for the user-visible fix.
    • It checks the starting state (input.matches(':focus-visible') is true) before acting.
    • It uses a real user.click and asserts :focus-visible on the trigger.
    • The regression it catches: the base code omitted focusVisible, so Chromium carried over the input's focus-visible state.
    • No changes needed.
  • R – FloatingFocusManager.test.tsx, "prevents focusVisible when returning focus after pointer close". This is a call-argument check, but it's the only jsdom proof of the pointer branch, since jsdom can't evaluate :focus-visible. The rename now matches the new behavior, and it's not redundant with the Chromium test.
  • F – FloatingFocusManager.test.tsx, "lets a text input keep its focus ring when returning focus after pointer close". The contract is real (the guard exists), but the name doesn't match the assertion. Fix as in Tests Copy supporting files from the Core repository #1.
  • Retained false positive: the call-argument checks are allowed here. The real behavior can't be observed in jsdom, and the Chromium test covers it for the main path.
  • Not requested: a Chromium test for the keyboard-close path, which existing tests already cover at the same owner.
  • Verification limits: I didn't run any tests. The earlier records say the guard and focusVisible: false mutations each turn a test red; I didn't reproduce that.

Verdict

Approve after nits - the only actionable item is the low-severity test name/assertion mismatch.


🤖 Review generated with Claude Code

@jjenzz

jjenzz commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

Addressing #6351 (comment)

All four findings are fixed in 6486b4b:

  • Text-input return targets (Bugs Copy supporting files from the Core repository #1): A text input always shows its focus ring when focused, so passing focusVisible: false there would hide a ring the browser normally shows. I now skip focusVisible: false when the return target is a typeable element, and added a test for an input return target after a pointer close.
  • Combobox test interaction: The test now uses user.click on the option instead of fireEvent, so it goes through the real pointer sequence.
  • Misleading test comment: I removed the comment that described a key press the test never performs.
  • Source comment: I reworded it to explain that the previously focused element's focus-visible state carries over, and why text inputs are exempt.

🤖 Comment posted by Claude Code

@jjenzz

jjenzz commented Nov 25, 2026

Copy link
Copy Markdown
Member Author

PR review

One informational note (Bugs #1); nothing here blocks the merge. The change adds one else if branch to FloatingFocusManager's return-focus microtask. After a pointer, touch or pen close, it passes focusVisible: false when returning focus, unless the target is typeable. Keyboard closes still get focusVisible: true, and programmatic closes (closeType === '') still leave the decision to the browser. I didn't run any tests or browsers, so I'm relying on recorded verification for observed :focus-visible behavior.

These are the paths I checked against the current code at 17858be6:

  • Tab-out after a mouse interaction. A focus-out close maps through getEventType to lastInteractionType || 'keyboard'. The document keydown capture listener resets lastInteractionTypeRef to 'keyboard' (FloatingFocusManager.tsx:400-402). So a keyboard user who tabs out after clicking inside the popup is still classified as a keyboard close, and the new branch can't hide their ring.
  • Virtual clicks and assistive-technology activation. A click that isVirtualClick recognizes, such as one with detail: 0 (FloatingFocusManager.tsx:53-59, 64-66), is classified as 'keyboard', so it takes the focusVisible: true branch.
  • Programmatic and controlled closes. These keep closeType === '', which bypasses the new branch. The controlled-close cases in the existing test at FloatingFocusManager.test.tsx:1786-1812 still expect exactly { preventScroll: true }, and that matches the code.
  • Native behavior. After a mouse activation, a native control that gets focus doesn't show a focus ring. The new branch matches that for non-text targets, and the text-input exemption keeps the always-visible ring that browsers give text fields.

Previous decisions, checked again:

  • Text-input focus ring: fixed. The guard is at FloatingFocusManager.tsx:953.
  • Combobox user.click test, removed test comment, source comment rewording, renamed test title: all fixed in the current code.
  • Non-text inputs (checkbox, radio, range) still exempted by isTypeableElement: this stays deferred. TYPEABLE_SELECTOR is input:not([type='hidden']):not([disabled]),[contenteditable]…,textarea… (constants.ts:4-6), so the recorded mechanism still holds. I found no new consumer evidence that would change the recorded reason.

Remaining risks:

Bugs (1)

1. ℹ️ Screen-reader presses that Chrome reports as mouse pointers now get focusVisible: false

Location: packages/react/src/utils/popups/focus/FloatingFocusManager.tsx:953

} else if (closeType !== '' && !isTypeableElement(tabbableReturnElement)) {
  focusOptions.focusVisible = false;
}

onPointerDown stores event.pointerType || 'keyboard' (FloatingFocusManager.tsx:387-388), and getEventType returns event.pointerType first. Neither checks isVirtualPointerEvent. The repository's own note at utils/popups/event.ts:31-33 says Chrome sends a TalkBack, VoiceOver or NVDA press as a 1x1 pointerType: 'mouse' pointerdown.

Failure scenario: A sighted screen-reader user in Chrome activates a Menu or Select item through the screen reader's click action. The close is classified as 'mouse', so focus returns to the trigger with focusVisible: false and the ring is forcibly hidden. Before this change, the browser's own heuristic decided. This is unverified in a real screen reader, the classification logic predates this diff, and the effect is only whether a ring shows, so it's a note.

Fix (optional): Treat virtual pointer events as keyboard where the interaction type is recorded, for example isVirtualPointerEvent(event) ? 'keyboard' : event.pointerType || 'keyboard'. Or only force false for non-virtual pointers.

Test audit

There are no actionable test-audit findings. I read all nine bundle files through Kody search: BASE-UI.md, SKILL.md, CAMPAIGN.md, references/audit.md, openclaw-testing.md, references/package-and-docker.md, writing-tests.md, boundary-scenarios.md and fixtures.md. Per BASE-UI.md, the OpenClaw-specific commands, budgets and CI routing don't apply here, and the Base UI pnpm test:jsdom / pnpm test:chromium conventions take their place.

I marked each changed test R (retain); none needed to be fixed, merged with another test or deleted:

  • R — ComboboxPopup.test.tsx "does not show the focus ring on the trigger after typing and then picking an item with a pointer" (Chromium only, via it.skipIf(isJSDOM)). This is the main behavioral test for the change. It checks the real :focus-visible state in a real browser and confirms the starting state first (input.matches(':focus-visible') is true before the click). It uses user.click on the option, as the repository guidelines require. The regression it catches: a pointer close leaves the ring on the return target. The recorded mutation check showed it fails when the focusVisible: false branch is removed.
  • R — FloatingFocusManager.test.tsx "prevents focusVisible when returning focus after pointer close" (jsdom). This asserts the arguments passed to focus(), which the audit rules usually reject as an implementation-detail check. I kept it because jsdom can't observe :focus-visible. It also matches the keyboard test next to it ("passes focusVisible when returning focus after keyboard close"), and it covers the shared FloatingFocusManager contract for every popup, not only Combobox. It doesn't duplicate the Chromium test.
  • R — FloatingFocusManager.test.tsx "does not pass focusVisible: false when returning focus to a text input after pointer close" (jsdom). The title now describes what the test asserts. The exact-argument check ({ preventScroll: true }) fails if focusVisible: false is added, and the recorded mutation check confirmed that.
    • Limit: no test in this diff checks in a browser that a text-input return target still matches :focus-visible. That behavior rests on the recorded manual Chromium check.
    • I'm not asking for a new test. It would be optional, and only worth adding if the call-argument check ever becomes fragile.
  • No test-only production hooks, mocks that supply the asserted behavior, or deleted coverage were added. The existing not.toHaveBeenCalledWith(objectContaining({ focusVisible: true })) checks at lines 1791 and 1810 still guard the programmatic-close contract.

Limits: I didn't run any tests or mutation checks myself. Pass/fail and mutation results come from the recorded round-2 and round-3 verification.

Verdict

Approve - the only finding is an optional ℹ️ note; earlier feedback is fixed or stays deferred with no new evidence.


🤖 Review generated with Claude Code

This branch has not been deployed

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

Labels

component: combobox Changes related to the combobox component. scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[combobox] Returned focus shows the keyboard focus ring after a mouse pick when the user typed first

2 participants