kobaltedev / kobalte

A UI toolkit for building accessible web apps and design systems with SolidJS.
https://kobalte.dev
MIT License
1.22k stars 62 forks source link

Select is out of sync in `0.10.0`. #252

Closed fabien-ml closed 1 year ago

fabien-ml commented 1 year ago

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 https://github.com/kobaltedev/kobalte/issues/229#issuecomment-1689992206

jcmonnin commented 10 months ago

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.