Tropix126 / fluent-svelte

A faithful implementation of Microsoft's Fluent Design System in Svelte.
https://fluent-svelte.vercel.app
MIT License
606 stars 26 forks source link

Rethinking how ComboBox handles values. #25

Closed Tropix126 closed 2 years ago

Tropix126 commented 2 years ago

Currently, our ComboBox component usage looks something like this:

<ComboBox value="item" items={[
    { name: "Item" }
]} />

"Selection" occurs when the name of the item matches the value passed in (or the value set by the developer). This has some advantages and disadvantages. The main advantage is that matching based on name means that we can bind the value of the input in searchable mode and use the same input for matching selection. This has some drawbacks, though. Items cannot be assigned a separate value from their name. Names must be unique for the ComboBox to behave as expected, and it can overall be a mess using a readable case system. This will need a bit of thinking on my part on how we should handle this. This would techncially be a breaking change under semver, but I consider undocumented components as in the 0.x stage.

alkanna commented 2 years ago

As far as I can see, other libraries went with a selectedId approach, making what we can put in items a lot more flexible. Do you think we could have something similar to what Carbon Components does ? They seem to dynamically create only one input element on selection, which works natively with forms. It looks like it has all the perks and none of the cons to me. See here : https://carbon-components-svelte.onrender.com/components/ComboBox

Tropix126 commented 2 years ago

So I think i've thought of an approach that i'm happy with. Essentially what will happen is that "value" (the currently selected item) and the "search value" (the contents of the editable combobox's search input) will be separate.

Tropix126 commented 2 years ago

implemented as of 537b1cd30b83aa1dd52a9791c27b3a03068812e4 (1.4.1). technically a breaking change, but this is an undocumented component