Skip to content
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's onChange also fires on no change #3202

Closed
matijs opened this issue May 14, 2024 · 3 comments
Closed

Combobox's onChange also fires on no change #3202

matijs opened this issue May 14, 2024 · 3 comments
Assignees

Comments

@matijs
Copy link

matijs commented May 14, 2024

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

2.0.3

What browser are you using?

Safari, Firefox

Describe your issue

Acoording to the docs, the onChange prop of a Combobox

…is called when a new option is selected’ (emphasis mine).

If a user clicks outside the Combobox without having selected an option, or when the user selects the same option that was already selected, the onChange handler also fires.
It's easy enough to work around, but it feels like the handler should only fire on an actual change :)

@RobinMalfait
Copy link
Collaborator

Hey!

That should definitely not be the case, my guess is that you are defining an array of objects inside your render function and therefore each option is going to be a new instance of the object every time the component rerenders.

Can you share a minimal reproduction repo?

@RobinMalfait RobinMalfait self-assigned this May 28, 2024
@RobinMalfait
Copy link
Collaborator

Hey! Going to close this one since we haven't heard back, but feel free to reopen a new issue if you're able to provide a minimal reproduction of this 👍

@matijs
Copy link
Author

matijs commented May 29, 2024

@RobinMalfait ah, will do, I had not found the time just yet. Your guess kind of helped in that indeed each option is a new instance (we use Combobox as a autosuggest) and that would explain firing onChange. However, with a fixed array defined outside of the render function reselecting an already selected option does seem to fire an undesired onChange.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants