-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ensure that there is always an active option in the Combobox
#1279
Conversation
This will ensure that the first non-disabled option is the active one if no other active options exist. This means that any time you search for something that the first result is the active one and you can just press <kbd>Enter</kbd> to activate the option. However, there are a few rules that we have to take into account: - If you just open the Combobox, and there is a `selected` Combobox.Option, then we can't make the first option the active one. The first selected Combobox.Option has precedence over this one. This is important and rather tricky because Combobox.Option's register themselves at some point (later) in time. - If you already have an active option, then that option should stay active. If it changes position, then the activeOptionIndex is adjusted to account for that. - If you "mouse leave" an option, then no option should be active. It will be re-enabled the moment you start typing OR if you re-open the Combobox. Otherwise, it can happen that you are at the bottom of the list, mouse leave, and we scroll all the way back up to make the first item the active one which is not good for UX reasons.
This pull request is being automatically deployed with Vercel (learn more). headlessui-react – ./packages/playground-react🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-react/9h5Bsv4GT3HhwzVDqnKSYSrLXC2Q headlessui-vue – ./packages/playground-vue🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-vue/94SD1kcxhUhjJZxhoQWHUoanhDcP |
Great contribution! The behaviour is slightly odd:
Screen.Recording.2022-03-29.at.11.00.19.AM.mp4 |
+1 to the behavior that @cabello explained, I am also experiencing this. Edit: I can also recreate the behavior like so, so it may not just be related to this change:
TL;DR: It takes 3 key downs to get to the second option in the list, when it should take 2. |
Super excited about this PR, can't wait to start using it. Hope the keyboard navigation issues get resolved before the release. |
@calthomson @cabello yikes, that happens when you work with selected values in your tests 😅 I could reproduce this in tests. Hold on, brb. Edit: #1281 |
Does not work at initial load when |
Is this already released in stable? |
Xerox invented this like 40 years ago, and headless can't figure this out. :) Waiting for the new build. |
is there also a way to deactivate this? |
Hi people, if you would like this to be deactivated use the emoji reactions, otherwise you are notifying everyone participating in this issue with non helpful "me too" comment. |
Are there any alternatives to remove this functionality? Kinda like a I am trying to replicate the "freeSolo" of material ui's autocomplete |
To trick this into being "disabled" you can use the custom values from the docs: https://headlessui.com/react/combobox#allowing-custom-values
|
This PR ensures that the first non-disabled
Combobox.Option
will be the active one if no other active option exists.This should improve the general UX of the
Combobox
component, because now you can search and immediately press Enter to choose that option instead of searching, pressing ArrowUp and then pressing Enter.Some rules that apply:
Combobox.Option
registers itself and is selected, then the first selected option will become the active one.This 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
.