fix(multi-select): render checkboxes for form data (#1835)

* chore: downgrade docs to svelte 3 for compatibility
* chore(multi-select): keep checkboxes rendered in DOM
* Display ListBox via CSS

See #1742
This commit is contained in:
Enrico Sacchetti 2023-10-26 21:21:37 -04:00 committed by GitHub
commit 7ba52df3a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 87 additions and 195 deletions

View file

@ -11,7 +11,12 @@
## Default
By default, items will be ordered alphabetically based on the `item.text` value. To prevent this, see [#no-alphabetical-ordering](#no-alphabetical-ordering).
By default, items will be ordered alphabetically based on the `item.text` value.
To prevent this, see [#no-alphabetical-ordering](#no-alphabetical-ordering).
MultiSelect provides interactivity for a list of checkbox inputs. Those
checkboxes will remain rendered in the DOM and are submittable within forms.
Checkbox attributes can be adjusted via the `itemToInput` prop.
<MultiSelect titleText="Contact" label="Select contact methods..."
items="{[{id: "0", text: "Slack"},
@ -73,6 +78,34 @@ Use the `itemToString` prop to format the display of individual items.
sortItem="{() => {}}"
/>
## Format checkbox values
Use the `itemToInput` prop to customize the user-selectable checkbox values.
This will also override the underlying hidden inputs used for form submission.
For example:
```js
(item) => ({name: `Contact_${item.id}`], value: item.id})
```
The above function sets the `name` attribute to
`Contact_0` (respective to each item's `id`) for every hidden input that
renders, along with each respective item's `id` set to the `value` attribute.
<MultiSelect
itemToInput={(item) => ({name: 'contact', value: item.id})}
titleText="Contact"
label="Select contact methods..."
items="{[
{id: "0", text: "Slack"},
{id: "1", text: "Email"},
{id: "2", text: "Fax"}
]}"
/>
## Top direction
Set `direction` to `"top"` for the dropdown menu to appear above the input.
@ -159,4 +192,4 @@ Use the `disabled` property in the `items` prop to disable specific items.
{ id: "1", text: "Email", disabled: true },
{ id: "2", text: "Fax" },
]}
/>
/>