Repository navigation
[menu] Limit WebKit selection state to focused filter input - #5868
Conversation
commit: |
Bundle size
PerformanceTotal duration: 484.43 ms +31.32 ms(+6.9%) | Renders: 76 (+0) | Paint: 890.58 ms +56.39 ms(+6.8%)
10 tests within noise — details Metric alarms
…and 2 more metric alarms — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
This comment was marked as resolved.
This comment was marked as resolved.
|
@claude review low |
PR reviewNo findings. The change is behaviourally sound on the paths I could verify from source. A few notes on residual risk and verification limits:
VerdictApprove - no correctness or regression defect survived review; the only loose end is the dropped comment documenting why the attribute is WebKit-only. 🤖 Review generated with Claude Code · Opus 5 (High) · |
PR reviewOne merge-blocking accessibility bug: the new unmount cleanup can clear Bugs (1)1. 🔴 Reconcile input focus state when the effect mountsLocation: React.useEffect(() => () => store.set('inputFocused', false), [store]);The flag is set only by
Failure scenario: arrowing still moves the highlight and Fix: read the real focus when the effect mounts. React runs all passive cleanups before passive mounts, so this also runs after the old input's cleanup in the keyed case: const inputRef = React.useRef<HTMLInputElement>(null);
const ref = useMergedRefs(forwardedRef, inputRef);
React.useEffect(() => {
// Focus can land before this runs (`autoFocus`, or a keyed replacement whose predecessor's
// cleanup ran after it), so read it instead of relying on the focus event alone.
const input = inputRef.current;
store.set('inputFocused', input != null && activeElement(ownerDocument(input)) === input);
return () => store.set('inputFocused', false);
}, [store]);Also pass it('keeps selection state for an auto-focused input in Strict Mode', async () => {
const { user } = await render(<Test autoFocus />); // `autoFocus` passed through to Menu.Input
await waitFor(() => expect(screen.getByRole('searchbox')).toHaveFocus());
await user.keyboard('[ArrowDown]');
expect(screen.getByRole('menuitem', { name: 'Apple' })).toHaveAttribute('aria-selected', 'true');
});VerdictRequest changes - a stale focus flag can disable the WebKit selection workaround while the input is focused. 🤖 Review generated with Claude Code |
|
Addressed the focus-state race in 636e242.
I added regression tests for Verification:
Safari VoiceOver output was manually verified. |
Safari VoiceOver was announcing a filterable menu item as selected and with an incorrect count while navigating on my older operating system (see the recording below). We originally added
aria-selectedto support arrow-key navigation in Safari only, but it was also being applied when they used their VoiceOver keys.This change exposes
aria-selectedonly on the highlighted item while its owning filter input has focus so VO-key navigation is not broken. It removes the attribute on blur, including when focus moves into a filterable submenu. Plain menus and other browser engines continue without this selection state.We recognize that
aria-selectedis not a valid state formenuitem, so this ensures a narrow compatibility workaround, not a recommended ARIA pattern: it was the simplest targeted fix we found for arrow-key navigation with Safari and VoiceOver. The focus and WebKit guards limit where the attribute appears.Validation:
pnpm test:jsdom MenuFilterRoot --no-watch,pnpm test:chromium MenuFilterRoot --no-watch,pnpm typescript,pnpm eslint,pnpm stylelint, andpnpm prettier.CleanShot.2026-10-02.at.10.38.41.mp4