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

Combobox values derived from options leads to edge cases #217

Closed stefan-ernst closed 1 year ago

stefan-ernst commented 1 year ago

Describe the bug

When trying to control combo box options and values externally, there can be edge cases because the selected options in "multiple" mode seem to be controlled by the available options. If you filter down the options, the values which are dependent on the options disappear from the combobox.

To Reproduce Steps to reproduce the behavior:

  1. Create a combobox with multiple=true
  2. Add values via an array []
  3. Add options via an array ["one","two","three"]
  4. Add option "one" to values
  5. Filter the combobox options by searching the input field to "three"
  6. Selected option "one" should disappear

Expected behavior Result filtering should have no impact on selected options

Screenshots SCR-20230509-e4r SCR-20230509-e56

Desktop (please complete the following information):

fabien-ml commented 1 year ago

Hi, thanks for reporting the issue. Maybe its related to #189

stefan-ernst commented 1 year ago

Hi, yes I think it goes a bit further than that as the selected option will then also replace the existing values array. If you want I can try to submit a PR for this, I think the values and option lists need to be separated. I'm not too familiar with solid yet but I can give it a try

fabien-ml commented 1 year ago

Yes, my problem is that both selected values and options are the same objects. I haven't found a solution to have a "copy" of the option when you select it so it will be independent of the combobox options.

martinpengellyphillips commented 1 year ago

Do you need to copy the option itself? In solid-select I use lists for the value and options so you can share the same object but still manage separately.

fabien-ml commented 1 year ago

Do you need to copy the option itself? In solid-select I use lists for the value and options so you can share the same object but still manage separately.

In solid-select the user provide all options and you filter internally, right ?

In Kobalte's Combobox it's the user responsibility to give a list of filtered options, so I don't have access to all.

stefan-ernst commented 1 year ago

We could pass in the list of the selected values as well, or have that as an option when the multiple prop is set to true? Would not be as ergonomic but reduce the internal complexity

martinpengellyphillips commented 1 year ago

In solid-select the user provide all options and you filter internally, right ?

No. In solid-select the options are reactive and so filtering happens outside. I just also provide a handy helper (createOptions) for that.

fabien-ml commented 1 year ago

Fixed in v0.10.0