Skip to content

fix(ComboBox): keep the popover open when pressing a non-field part of it - #11003

Draft
zecka wants to merge 1 commit into
adobe:mainfrom
zecka:fix/combobox-popover-press-11002
Draft

zecka wants to merge 1 commit into
adobe:mainfrom
zecka:fix/combobox-popover-press-11002

Conversation

@zecka

@zecka zecka commented Nov 19, 2026 •

Copy link
Copy Markdown

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 with relatedTarget: null. onBlur in useComboBox only ignores a blur into the trigger button or into the popover, so it calls state.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:

Press on Chromium Firefox WebKit
Popover padding closes closes closes
Gap between buttons closes closes closes
Plain text closes closes closes
RAC Button stays open stays open stays open
Native <button> stays open stays open closes

The RAC Button survives in WebKit because useFocusable always sets tabIndex, 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. useOverlay ignores a null relatedTarget, and a non-modal popover isn't dismissable, so nothing closed it.

The change

While the popover is open, useComboBox listens to mousedown on popoverRef and calls preventDefault(), unless the target is a field that needs focus. Fields are whatever willOpenKeyboard accepts (text inputs, textarea, contenteditable), plus select and input[type=range] so their pointer interaction still works.

  • The listener is native because usePress stops propagation of mousedown. A React onMouseDown on the popover would never see a press on a RAC Button.
  • It does nothing when the input is inside 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 and shouldCloseOnBlur is false there. Tapping the tray background still blurs the input and hides the virtual keyboard.
  • I used preventDefault instead of the existing preventFocus helper. preventFocus lets the focus move happen and then restores focus with window capture listeners. On a native button in WebKit it waits for a focusin that never comes, which would leave the input blurred without the state knowing. useListBoxSection and useSelectableCollection already call preventDefault on mousedown for 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

  • Text in the popover that isn't a field can no longer be selected with a mouse drag.
  • Buttons in the popover no longer take focus on click. click and onPress still fire, and focus stays in the input. This also fixes the outside-click problem above for buttons.
  • A field inside the popover still takes focus. After it has focus, an outside click still doesn't close the popover. That was already the case before this PR and I left it out of scope. It seems related to the groupRef plan in ComboBox: support shouldCloseOnInteractOutside #9761.
  • Virtual focus, keyboard navigation, aria-activedescendant and allowsCustomValue behave 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 RAC Button and plain text. Each press keeps the popover open and focus in the input, and fireEvent.mouseDown returns false. The button's onPress still fires. An outside click then still commits and closes. Fails before the fix, passes after.
  • Same file, "should let fields inside the popover take focus". A text input, a select and 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 RAC Button, 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: WithPopoverContent under 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/ai Chat.browser.test.tsx). They fail the same way on my machine with the useComboBox change 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.tsx tests are skipped in the repo, so they don't run.

Manual check in Chrome, on the WithPopoverContent story 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 set aria-activedescendant to "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

  • Only changes docs, tests, CI, or development tools. Nothing shipped to users changes.
  • Fixes a bug or improves existing code without changing how apps use it.
  • Adds a feature or API while keeping existing usage working.
  • May break existing usage or require changes in apps that use this code.

✅ PR Checklist

  • I followed the contributing guide.
  • I tested this change locally and included the results in Test Instructions, or explained why testing does not apply.
  • I understand and can explain every change in this PR. If I used AI assistance, I followed the AI contribution guidance.

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

…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 snowystinger left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this wouldn't work for touch

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

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 (

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

There are two cases:

  1. Pressing the popover padding. It closes even without custom content, in S2 and v3 too.
  2. 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ComboBox: pressing a non-field part of the Popover closes it

2 participants