mirror of
https://github.com/carbon-design-system/carbon-components-svelte.git
synced 2025-09-19 20:09:35 +00:00
* chore(deps-dev): upgrade carbon-components to v10.38.0 * feat(text-input): support read-only variant * docs: use consistent lingo for inline variant examples * docs(popover): add Popover alignment example * fix(file-uploader): adjust markup to avoid accessibility errors Ref:0dfde60e3
* fix(inline-loading): use error filled icon * fix(inline-loading): render iconDescription as title in error/warning icons Ref:51c53c923
* fix(structured-list): update accessibility attributes * fix(tooltip-definition): use span instead of div Ref:cb6de3025
* fix(multi-select): close menu when blurring the last filterable option * fix(multi-select): open/focus field for filterable multiselect #635 * fix(multi-select): unblock focus when blurring input #635 * fix(combo-box): select correct item with keys, allow input after clearing #195 * fix(combo-box): update input text if item is selected * feat(combo-box): render checkmark icon for selected item * fix(ui-shell): toggle SideNav rail when clicking the hamburger menu #699 * fix(context-menu): update context menu classes #684 * docs(context-menu): improve demo instructions #684 * fix(context-menu): close menu when clicking anywhere
130 lines
No EOL
3.6 KiB
Text
130 lines
No EOL
3.6 KiB
Text
<script>
|
|
import { MultiSelect } from "carbon-components-svelte";
|
|
import Preview from "../../components/Preview.svelte";
|
|
</script>
|
|
|
|
### Default
|
|
|
|
By default, items will be ordered alphabetically based on the `item.text` value. To prevent this, see [#no-alphabetical-ordering](#no-alphabetical-ordering).
|
|
|
|
<MultiSelect titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### No alphabetical ordering
|
|
|
|
To prevent alphabetical item ordering, pass an empty function to the `sortItem` prop.
|
|
|
|
<MultiSelect titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
sortItem="{() => {}}"
|
|
/>
|
|
|
|
### Filterable
|
|
|
|
`$$restProps` are spread to the underlying input element.
|
|
|
|
<MultiSelect spellcheck="false" filterable titleText="Contact" placeholder="Filter contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Initial selected items
|
|
|
|
To select (or bind) items, pass an array of item ids to `selectedIds`.
|
|
|
|
<MultiSelect selectedIds="{["0", "1"]}" titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Multiple multi-select dropdowns
|
|
|
|
<FileSource src="/framed/MultiSelect/MultipleMultiSelect" />
|
|
|
|
### Format item display text
|
|
|
|
Use the `itemToString` prop to format the display of individual items.
|
|
|
|
<MultiSelect itemToString={item => {
|
|
return item.text + ' (' + item.id +')'
|
|
}} titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
sortItem="{() => {}}"
|
|
/>
|
|
|
|
### Top direction
|
|
|
|
Set `direction` to `"top"` for the dropdown menu to appear above the input.
|
|
|
|
<MultiSelect direction="top" titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Light variant
|
|
|
|
<MultiSelect light titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Inline variant
|
|
|
|
<MultiSelect type="inline" titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Extra-large size
|
|
|
|
<MultiSelect size="xl" titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Small size
|
|
|
|
<MultiSelect size="sm" titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
|
|
|
|
### Invalid state
|
|
|
|
<MultiSelect invalid invalidText="A contact method is required" titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Warning state
|
|
|
|
<MultiSelect warn warnText="One or more contact methods are not associated with your account" titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/>
|
|
|
|
### Disabled state
|
|
|
|
<MultiSelect disabled titleText="Contact" label="Select contact methods..."
|
|
items="{[{id: "0", text: "Slack"},
|
|
{id: "1", text: "Email"},
|
|
{id: "2", text: "Fax"}]}"
|
|
/> |