Ability to auto-activate the first matching option in Combobox #1320
-
Hello. I'm hoping there's a way to do this already, otherwise I'd like to propose it as a feature. Using the demo in the docs, if you type "T", you get three matching options, like this: ...but if you press "Enter" at this point, it just changes the box back to the default option ("Wade Cooper"). In my particular use case, this feels weird and unexpected. To get it to actually choose, say, the first option ("Tom Cook"), I have to press "Down" first before pressing "Enter". What I'd like: a way to force it so that, whenever options are visible, there is always an option activated (the first, by default), i.e. so it would look like this instead: This way, I can just type a few characters, and if the first option is the one I want, I can just hit "Enter" to select it, without having to press the "Down" arrow key first. Is there any way to achieve this behaviour with the existing API? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 10 replies
-
I attempted a hack: I passed a |
Beta Was this translation helpful? Give feedback.
-
Agree with the UI flow you have laid out. I think we could figure out a hacky way to allow it, but it is unlikely to be ideal and would have flaws. This seems like a good default, if not, I would like to see it as an option via a prop. |
Beta Was this translation helpful? Give feedback.
-
@callumlocke Something like this could be an improvement. The way the input works now, users can type in something and have the impression that they have selected something when they have not. Without some kind of rigorous front-end validation, it can lead to a confusing UX because the option won't have changed when a user may think it has. |
Beta Was this translation helpful? Give feedback.
-
Hey! Thank you for your suggestion! This should be fixed, and will be available in the next release. You can already try it using:
|
Beta Was this translation helpful? Give feedback.
-
Very interesting. I made an Autocomplete Component with Combobox. When the User hits Enter, I don't know if the user wants to enter a search or select the index item of 0. Therefore, I need a way to tell this apart. If activeIndex starts from 0, this problem cannot be solved. It would be nice to have props that can control the activeIndex. Do you have good ideas fir this? 🙏🏽 |
Beta Was this translation helpful? Give feedback.
Hey! Thank you for your suggestion!
Much appreciated! 🙏
This should be fixed, and will be available in the next release.
You can already try it using:
npm install @headlessui/react@insiders
oryarn add @headlessui/react@insiders
.npm install @headlessui/vue@insiders
oryarn add @headlessui/vue@insiders
.