react-spectrum: ComboBox with autofocus doesn't show its dropdown auto focused with `menuTrigger='focus'`

Discussed in https://github.com/adobe/react-spectrum/discussions/5462

<div type='discussions-op-text'>

Originally posted by austincrim November 22, 2023 I’m trying to build a CMD + K-like interface using a ComboBox inside of a Dialog. I want the ListBox options to always be visible, regardless if the Input has been typed in or manually focused (using the ComboBox menuTrigger prop).

I couldn’t find a way to do this in the docs. Any recommendations?

Here’s how it looks now, but I want the list of options to be visible as soon as the dialog is opened.

Stackblitz link

https://github.com/adobe/react-spectrum/assets/32459922/1cc5dca5-8ba1-4293-8005-9820f9ba74b5

As an aside, the React Spectrum support page still links to creating a new GitHub Issue, when it looks like you’ve switched to Discussions.

</div>

See https://github.com/adobe/react-spectrum/discussions/5462#discussioncomment-7647429 for more info. The gist is that the collection for the ComboBox is undefined/empty when the input gets autofocused since RAC collections need two renders to fully generate.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 3
  • Comments: 17 (8 by maintainers)

Most upvoted comments

Just chiming in that I haven’t forgotten about this, but we’re pretty busy with an upcoming release so I haven’t been able to look at this in-depth.

the keyboard virtual focus can be setup by doing something like https://github.com/adobe/react-spectrum/blob/2b05b6d984e1b37d4ac76f0bb305433d8f57d988/packages/%40react-aria/combobox/src/useComboBox.ts#L98-L108 and passing the keydown handlers to you input: https://github.com/adobe/react-spectrum/blob/2b05b6d984e1b37d4ac76f0bb305433d8f57d988/packages/%40react-aria/combobox/src/useComboBox.ts#L188. You may need to add/remove some additional onKeyDown behavior similar to what we do in useComboBox but not having a open state to flip on/off should make that easier. I’m not sure about the shouldFocusWrap issue, would need to dig.