Repository navigation
Conversation
…f it Pressing the popover padding, plain text, the gap between two buttons, or a native button in Safari moved focus to the body. The input then blurred with a null relatedTarget, so useComboBox committed the value and closed the menu. useComboBox now prevents the default action of mousedown inside the open popover, unless the target is a field that needs focus (text input, textarea, contenteditable, select, range input). It uses a native listener because usePress stops mousedown propagation, and it is skipped when the input sits inside the popover, as in the v3 mobile trays. Closes adobe#11002 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
snowystinger
left a comment
There was a problem hiding this comment.
what are some other ways that you could stop focus from moving off the input, what about pointer events none?
wouldn't a button inside the popover cause an issue always? why only in safari?
Did any other components have this issue and solve it?
| // usePress stops mousedown propagation. Skipped when the input is inside the popover (mobile trays). | ||
| useEvent( | ||
| popoverRef, | ||
| 'mousedown', |
There was a problem hiding this comment.
this wouldn't work for touch
There was a problem hiding this comment.
Which touch case do you mean? From what I understand, a tap still fires mousedown after touchend.
I made a codepen to test in real device (Google pixel 7a, chrome) (https://codepen.io/zecka/full/vEmLwzw) and with Playwright touch emulation, but I may be missing something.
|
|
||
| function isFieldTarget(target: Element | null, popover: Element | null): boolean { | ||
| for (let element = target; element && element !== popover; element = getParentElement(element)) { | ||
| if ( |
There was a problem hiding this comment.
i don't understand this if, why does it look for willOpenKeyboard? I'm imagining this is covering the same case as https://react-aria.adobe.com/ComboBox#item-actions but inside the popover there'd probably be some accessibility problems
There was a problem hiding this comment.
There are two cases:
- Pressing the popover padding. It closes even without custom content, in S2 and v3 too.
- Pressing extra buttons outside the ListBox. I keep them out of keyboard navigation on purpose. I get that this may not be a valid pattern, but mouse and touch only is fine for my use case.
willOpenKeyboard only lets a text field in the popover take focus. Happy to drop it, or limit the PR to case 1.
Note: I'm still working on this PR and have several checks to complete before it's ready for review. Since this PR was created with AI assistance, I need to carefully review everything. I'll mark it as ready for review once I'm done.
Closes #11002
Summary
Pressing a part of a ComboBox popover that isn't a field should leave the popover open and keep focus in the input. Today it closes the popover. This happens on the popover padding, on plain text, in the gap between two buttons, and in Safari on a native
<button>.The press moves focus to
body, so the input blurs withrelatedTarget: null.onBlurinuseComboBoxonly ignores a blur into the trigger button or into the popover, so it callsstate.setFocused(false), which commits the value and closes the menu. Options (preventFocusOnPress), section headers, and the ListBox padding and scrollbar already stop that focus move. The rest of the popover had nothing.Results with real Playwright clicks before the fix:
Button<button>The RAC
Buttonsurvives in WebKit becauseuseFocusablealways setstabIndex, so Safari focuses it. I also found that once a button inside the popover had focus, a later outside click no longer closed the popover in any of the three engines.useOverlayignores a nullrelatedTarget, and a non-modal popover isn't dismissable, so nothing closed it.The change
While the popover is open,
useComboBoxlistens tomousedownonpopoverRefand callspreventDefault(), unless the target is a field that needs focus. Fields are whateverwillOpenKeyboardaccepts (text inputs, textarea, contenteditable), plusselectandinput[type=range]so their pointer interaction still works.usePressstops propagation ofmousedown. A ReactonMouseDownon the popover would never see a press on a RACButton.popoverRef. That is the case for the v3 mobile trays (MobileComboBox,MobileSearchAutocomplete), which never had this bug: a blur into the tray dialog is already ignored andshouldCloseOnBluris false there. Tapping the tray background still blurs the input and hides the virtual keyboard.preventDefaultinstead of the existingpreventFocushelper.preventFocuslets the focus move happen and then restores focus with window capture listeners. On a native button in WebKit it waits for afocusinthat never comes, which would leave the input blurred without the state knowing.useListBoxSectionanduseSelectableCollectionalready callpreventDefaultonmousedownfor section headers and the scrollbar.Since the change is in the hook, it reaches the RAC ComboBox, the S2 ComboBox (built on RAC), and the v3 ComboBox and SearchAutocomplete on desktop.
Trade-offs
clickandonPressstill fire, and focus stays in the input. This also fixes the outside-click problem above for buttons.groupRefplan in ComboBox: support shouldCloseOnInteractOutside #9761.aria-activedescendantandallowsCustomValuebehave as before.📝 Test Instructions
New tests:
packages/react-aria-components/test/ComboBox.test.js, "pressing inside the popover" › "should keep the popover open and focus in the input when pressing a non-field part". It presses the popover padding, the gap between two buttons, a RACButtonand plain text. Each press keeps the popover open and focus in the input, andfireEvent.mouseDownreturnsfalse. The button'sonPressstill fires. An outside click then still commits and closes. Fails before the fix, passes after.selectand a range input are not prevented, and the text input takes focus. This one guards the exclusions, so it passes both before and after the fix.packages/react-aria-components/test/ComboBox.browser.test.tsx, "keeps the popover open when pressing a non-field part of it". Real Playwright clicks on the padding, the gap, text, a native button (the WebKit case) and a RACButton, then an outside click that closes. Fails before the fix and passes after, in Chromium, Firefox and WebKit.packages/@adobe/react-spectrum/test/combobox/ComboBox.test.js, "does not close when pressing the popover outside of an option" (v3). Fails before the fix, passes after.For S2 I ran a throwaway jsdom test, not committed, that pressed the S2 ComboBox popover and its ListBox wrapper. It failed before the fix and passed after.
New story:
WithPopoverContentunder React Aria Components/ComboBox. It reproduces the issue.Commands run locally on this branch:
yarn test: 386 suites, 8330 passed, 16 skipped.yarn test:ssr: 60 suites, 74 tests passed.yarn test:browser: 522 passed, 67 skipped, 5 failed. All 5 failures are in WebKit (DragAndDrop.browser.test.tsx, the three "should only drag from styled ... handles" tests, and two "scroll button" tests in@react-spectrum/aiChat.browser.test.tsx). They fail the same way on my machine with theuseComboBoxchange reverted, so I don't think this PR causes them. The ComboBox browser tests pass in all three browsers.yarn lint: exit 0 (format check,tsc, oxlint, package lint, constraints).The S2
Combobox.browser.test.tsxtests are skipped in the repo, so they don't run.Manual check in Chrome, on the
WithPopoverContentstory with Parcel 3 Storybook. With the popover open, I clicked the padding, the gap between the buttons, the text, the native button and "Reset selection". After each click the popover stayed open and focus stayed in the input. ArrowDown setaria-activedescendantto "Cat" and Enter selected it. "Reset selection" cleared the selection with the popover still open. The text field inside the popover took focus. The trigger button still toggled the popover, and an outside click closed it.Not checked by hand: Safari (WebKit is covered only by the Playwright test), touch on real iOS and Android devices, screen readers, RTL, high contrast.
Release impact
✅ PR Checklist
AI disclosure: the investigation, the fix, the tests and this description were written with Claude Code (Claude Opus 5.5). I will review them before marking this PR ready for review.
🧢 Your Project
🤖 Generated with Claude Code