Repository navigation
Conversation
snowystinger
left a comment
There was a problem hiding this comment.
Thanks for the PR, would you mind adding a storybook story to demonstrate the behaviour. The tests are good for regressions, but with how complex combobox is it'd be good to verify it manually in a real browser in addition to the jsdom tests
|
Added Storybook stories demonstrating the initially-empty |
| } | ||
| }; | ||
|
|
||
| export const ComboBoxAsyncInitiallyEmptyExample: ComboBoxStory = { |
There was a problem hiding this comment.
So I see a difference when i type "F", but the behaviour before and after is the same for "f". It doesn't open until I delete and re-type the "f", then they both open. I'm surprised that "f" works on the second time, but not the first. Any idea what's going on there? is it related to this?
There was a problem hiding this comment.
Yeah, the second try part is related. On main, typing "f" the first time still loads [Foo] into useAsyncList even though the menu stays closed. When you backspace, useAsyncList keeps [Foo] for a render while inputValue changes to "", which briefly opens the menu. Then load({filterText: ''}) resolves [], so it auto-closes and sets closedDueToEmpty.current = true. That's why typing "f" again opens on both branches.
I'm not sure why "f" vs "F" would behave differently on the first try though. Both the story (filterText.toLowerCase()) and useComboBoxState are case-insensitive, and lowercase works in the tests. Did "f" blur the input or hit a shortcut, or does it happen consistently on a fresh reload?
There was a problem hiding this comment.
I didn't notice it blur or hit a shortcut, it happened every time i tried it. Were you able to reproduce it?
There was a problem hiding this comment.
I just spun up Storybook locally on this branch (Chromium) and tested both ComboBoxAsyncInitiallyEmptyExample and ServerSideFilteringInitiallyEmpty, but I couldn't reproduce the difference. Both "f" and "F" opened the menu on the first keystroke for me.
Which browser/OS and story are you seeing that in? Also, if you inspect the wrapper when "f" fails to open, does .react-aria-ComboBox still have data-focused="true"? That might help narrow down whether something in the manager or browser setup is dropping focus or intercepting the key.
There was a problem hiding this comment.
I must've had something in my storybook cache, i cleared out everything and it's no longer different between the two. Thanks for also trying it out
snowystinger
left a comment
There was a problem hiding this comment.
I think this is ok, thanks for the PR
Closes #2333
Summary
Problem and intent: When an async ComboBox starts with an empty collection (e.g. an empty search string returns
[]) and does not setallowsEmptyCollection, typing the first character fails to open the menu once async results arrive. InuseComboBoxState,closedDueToEmpty(introduced in #9823) was only set when closing an already-open menu (triggerState.isOpen && filteredCollection.size === 0). On the first keystroke from a closed empty state (!triggerState.isOpen),open(null, 'input')is skipped while results are pending andlastValueupdates toinputValue; on the later render when items arrive,inputValue === lastValueandclosedDueToEmpty.currentisfalse, so the menu stays closed.Implementation:
packages/react-stately/src/combobox/useComboBoxState.ts, when an input change occurs while focused and closed withmenuTrigger !== 'manual', iffilteredCollection.size === 0 && !allowsEmptyCollection, setclosedDueToEmpty.current = trueso incoming async items open the menu cleanly on arrival.closedDueToEmpty.currentwhen opening due tofilteredCollection.size > 0 || allowsEmptyCollection, when blurring (setFocused(false), regardless ofshouldCloseOnBlur/isReadOnly), when manually toggling the menu closed (toggleMenu), and when closing upon single-selection change (displayValue !== lastValueRef.current). (Explicit dismissals viarevert()/commitValue()already cleared it.)packages/react-stately/test/combobox/useComboBoxState.test.jsandpackages/react-aria-components/test/ComboBox.test.js.📝 Test Instructions
useComboBoxState.tschange -> passing after):yarn test packages/react-stately/test/combobox/useComboBoxState.test.js -t "initially-empty" --runInBandshould open the menu when initially-empty controlled items load after typingreceivedisOpen === false).yarn test packages/react-aria-components/test/ComboBox.test.js -t "initially-empty" --runInBandComboBox itemsandListBox itemsuseAsyncListtests failed withlistboxstayingnull).onOpenChangecalled once with(true, 'input')on load and once with(false, undefined)on backspace to empty).Escapewhile async results are pending clears the pending open and keeps the menu closed.yarn format-> exited 0 (oxfmtacross 6,570 files)yarn test packages/react-stately/test/combobox/useComboBoxState.test.js --runInBand-> 20 passed (20 total)yarn test packages/react-aria/test/combobox/useComboBox.test.js --runInBand-> 6 passed (6 total)yarn test packages/react-aria-components/test/ComboBox.test.js --runInBand-> 53 passed (53 total)yarn test packages/@adobe/react-spectrum/test/combobox/ComboBox.test.js --runInBand-> 216 passed (216 total)yarn test packages/@react-spectrum/s2/test/Combobox.test.tsx --runInBand-> 7 passed (7 total)yarn test:ssr packages/react-aria-components/test/ComboBox.ssr.test.js --testTimeout=180000-> 2 passed (2 total; first cold run timed out at 120s starting the local SSR server, warm rerun passed in 30.1s)yarn lint-> exited 0 (format:check,tsc --noEmit,oxlint packageswith 0 warnings/0 errors across 2,847 files,scripts/lint-packages.js,yarn constraints)Covered:
useComboBoxStatehook tests, RACComboBox(ComboBoxitems andListBoxitems withuseAsyncList), SpectrumComboBox, S2Combobox, ComboBox SSR hydration, blur/Escape cancellation, and monorepo lint/typecheck. Not manually verified: Storybook visual testing, Playwright browser suite (yarn test:browser), or screen readers.Release impact
✅ PR Checklist
AI assistance was used during root-cause analysis and test authoring; all changes follow
AGENTS.mdandCONTRIBUTING.md, were reviewed line by line, and were verified locally with the commands above.🧢 Your Project
Independent open-source contribution.