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

Select is out of sync in 0.10.0. #252

Closed
fabien-ml opened this issue Aug 24, 2023 · 1 comment
Closed

Select is out of sync in 0.10.0. #252

fabien-ml opened this issue Aug 24, 2023 · 1 comment

Comments

@fabien-ml
Copy link
Collaborator

fabien-ml commented Aug 24, 2023

When having a controlled value, I see the select being out of sync in 0.10.0. It can be reproduced in the documentation page.

  1. Go to Select Controlled value example
  2. Select Apple
  3. Deselect Apple
  4. Select box still shows Apple, controlled value is empty (eg. it shows Your favorite fruit is: .). This happens most of the time for me, but not always.

Luckly for me I need disallowEmptySelection: true, so that issue is currently not relevant for me (I had to specify this explicitly, since the default value changed in 0.10.0. This is the reason I started to look into this).

Originally posted by @jcmonnin in #229 (comment)

@jcmonnin
Copy link

Sorry, unfortunately I still got an issue related to out of sync controlled value in single select.

Please check example here and follow the explanations on the page:
https://stackblitz.com/edit/github-vhpnzf-y71c4s?file=src%2FApp.tsx

In a nutshell, it looks like the Select value needs to be null in order have correct behavior when unselecting an element, however it's not what TypeScript expect (eg. it expects Fruit | Fruit[] | undefined).

Generally, I think null should be avoided:
https://medium.com/@hbarcelos/why-i-banned-null-from-my-js-code-and-why-you-should-too-13df90323cfa

Therefore, in my opinion, onChange should give undefined when nothing is selected, and value should expect undefined for unselected state.

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