feat(multi-select): make MultiSelect slottable (#1183)

This commit is contained in:
metonym 2022-03-19 09:15:58 -07:00 committed by GitHub
commit 1017e80198
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 71 additions and 17 deletions

View file

@ -6935,19 +6935,26 @@
}
],
"moduleExports": [],
"slots": [],
"events": [
"slots": [
{
"type": "dispatched",
"name": "blur",
"detail": "FocusEvent | CustomEvent<FocusEvent>"
},
"name": "__default__",
"default": true,
"fallback": "{itemToString(item)}",
"slot_props": "{ item: MultiSelectItem; index: number }"
}
],
"events": [
{
"type": "dispatched",
"name": "select",
"detail": "{ selectedIds: MultiSelectItemId[]; selected: MultiSelectItem[]; unselected: MultiSelectItem[]; }"
},
{ "type": "dispatched", "name": "clear", "detail": "null" },
{
"type": "dispatched",
"name": "blur",
"detail": "FocusEvent | CustomEvent<FocusEvent>"
},
{ "type": "forwarded", "name": "keydown", "element": "input" },
{ "type": "forwarded", "name": "keyup", "element": "input" },
{ "type": "forwarded", "name": "focus", "element": "input" }

View file

@ -13,6 +13,12 @@ By default, items will be ordered alphabetically based on the `item.text` value.
{id: "2", text: "Fax"}]}"
/>
### Custom slot
Override the default slot to customize the display of each item. Access the item and index through the `let:` directive.
<FileSource src="/framed/MultiSelect/MultiSelectSlot" />
### No alphabetical ordering
To prevent alphabetical item ordering, pass an empty function to the `sortItem` prop.

View file

@ -0,0 +1,33 @@
<script>
import { MultiSelect } from "carbon-components-svelte";
</script>
<MultiSelect
titleText="Contact"
label="Select contact methods..."
items="{[
{ id: '0', text: 'Slack' },
{ id: '1', text: 'Email' },
{ id: '2', text: 'Fax' },
]}"
let:item
let:index
>
<div>
<strong>{item.text}</strong>
</div>
<div>
id: {item.id} - index:
{index}
</div>
</MultiSelect>
<style>
:global(.bx--list-box__menu-item, .bx--list-box__menu-item__option) {
height: auto;
}
:global(.bx--checkbox-label-text) {
display: block;
}
</style>