-
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
Combobox selects first item on blur #2932
Comments
Hey thanks for reporting this! I've been able to reproduce this issue. It only happens (at least for me) when I open the combobox and immediately move the mouse away and click, however if I open the combobox and first hover over items in the dropdown and then move away and click, it doesn't happen. We'll look into it 👍 |
same happens on @headlessui/react: 1.7.18 |
When you use the arrow keys to move up and down and then click outside, whichever option currently active will be selected. |
yes |
@reinink do you work on solution for react lib too? |
Hey folks, thanks for your patience on this one. I've had a closer look at this today, and realizing now that this is actually expected behavior. By default the <Combobox value={selectedPerson} onChange={setSelectedPerson} nullable> Here's an updated reproduction that uses this prop: https://stackblitz.com/edit/vitejs-vite-ncgpkn?file=src%2FApp.vue You can read more about the The combobox behaves oddly when you pass it a Hope that helps! 🤙 |
First of all thanks for the response, in the demo you sent the problem still exists. try to move up and down with the arrows and then click outside, it will select the focused one... |
I can confirm that the issue is still present after setting the |
After additional testing I've noticed that you have to set the initial value of the ref to But all in all I think this behaviour is really awkward and counterintuitive. |
Hey folks! Just wanted to let you know that the upcoming v2 release is going to make the combobox "nullable by default". You can read more about this change in #3064. Thanks for sharing all this feedback! 👍 |
@reinink I've tested this in the react v2 alpha and the issue still exists with or without the nullable prop – if there's an "active" option in Should this be re-opened? |
@DanWebb Hey! So we never published an alpha release with this new behavior, but it is available in the latest v2.0.0 release that went out yesterday. You can test out this new behavior in the updated docs here: https://headlessui.com/react/combobox |
So, testing this on v2 shows that it seems to be still broken. Clicking away from the combobox behaves exactly the same as hitting the return key (enter). What I think is happening is that when combobox displays options, the first option is sort of "hovered" by default. Hovering over that option and then clicking away has the desired behavior of closing the options. Ive tested this by hitting the down arrow and clicking away and noted that the second option in the list is what ends up triggering the onChange on the combobox. |
@reinink Thanks! I've tested on 2.0.3 this morning and it all seems to be fixed 👍 @djerraballi I did have to move to the new components |
This is also an issue when a value is already selected. I have used the same demo used above demo on Stack blitz Instead of Expected behaviour: Actual behaviour: |
What package within Headless UI are you using?
@headlessui/vue
What version of that package are you using?
v1.7.17
What browser are you using?
Chrome
Reproduction URL
Basic example on stackblitz
Describe your issue
When a
Combobox
that does not already have a value is closed by clicking outside the element, the first value is selected.Steps to reproduce:
v-model = undefined
)If the selection is cancelled by pressing the esc key the issue does not occur.
The text was updated successfully, but these errors were encountered: