docs(combo-box): improve docs

This commit is contained in:
Eric Liu 2025-04-20 15:10:24 -07:00
commit d907d000a6

View file

@ -3,6 +3,8 @@
import Preview from "../../components/Preview.svelte"; import Preview from "../../components/Preview.svelte";
</script> </script>
ComboBox combines a text input with a dropdown menu. Use it to let users select from a predefined list of options or enter custom values.
`ComboBox` is keyed for performance reasons. `ComboBox` is keyed for performance reasons.
<InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton> <InlineNotification svx-ignore lowContrast title="Note:" kind="info" hideCloseButton>
@ -11,6 +13,8 @@
## Default ## Default
Create a combobox with a title and placeholder text. Each item requires a unique `id` and `text`.
<ComboBox titleText="Contact" placeholder="Select contact method" <ComboBox titleText="Contact" placeholder="Select contact method"
items={[ items={[
{id: "0", text: "Slack"}, {id: "0", text: "Slack"},
@ -20,12 +24,14 @@ items={[
## Custom slot ## Custom slot
Override the default slot to customize the display of each item. Access the item and index through the `let:` directive. Override the default slot to customize how each item displays. Access the item and index through the `let:` directive.
<FileSource src="/framed/ComboBox/ComboBoxSlot" /> <FileSource src="/framed/ComboBox/ComboBoxSlot" />
## Hidden label ## Hidden label
Set `hideLabel` to `true` to visually hide the label while keeping it accessible to screen readers.
<ComboBox hideLabel titleText="Hidden Label" placeholder="Select contact method" <ComboBox hideLabel titleText="Hidden Label" placeholder="Select contact method"
items={[ items={[
{id: "0", text: "Slack"}, {id: "0", text: "Slack"},
@ -35,6 +41,8 @@ items={[
## Initial selected id ## Initial selected id
Set `selectedId` to pre-select an item when the combobox loads.
<ComboBox titleText="Contact" placeholder="Select contact method" <ComboBox titleText="Contact" placeholder="Select contact method"
selectedId="1" selectedId="1"
items={[ items={[
@ -45,33 +53,39 @@ items={[
## Reactive example ## Reactive example
See how the combobox responds to user input and selection changes.
<FileSource src="/framed/ComboBox/ReactiveComboBox" /> <FileSource src="/framed/ComboBox/ReactiveComboBox" />
## Clear selection ## Clear selection
To programmatically clear the selection, access the component instance using the [bind:this](https://svelte.dev/docs#bind_element) directive and invoke the `ComboBox.clear()` accessor. Use `bind:this` to access the component instance and call `ComboBox.clear()` to programmatically clear the selection.
Specify `focus: false` in the method options to avoid re-focusing the input. Set `focus: false` in the method options to prevent re-focusing the input.
<FileSource src="/framed/ComboBox/ComboBoxClear" /> <FileSource src="/framed/ComboBox/ComboBoxClear" />
## Multiple combo boxes ## Multiple combo boxes
See how to manage multiple comboboxes in a form.
<FileSource src="/framed/ComboBox/MultipleComboBox" /> <FileSource src="/framed/ComboBox/MultipleComboBox" />
## Filterable ## Filterable
Enable filtering to let users search through the options.
<FileSource src="/framed/ComboBox/FilterableComboBox" /> <FileSource src="/framed/ComboBox/FilterableComboBox" />
## Filterable with custom label ## Filterable with custom label
Combine a custom label `itemToString` with the filterable option (e.g., internationalization). Set `itemToString` to customize how items display in the filterable combobox.
<FileSource src="/framed/ComboBox/FilterableComboBoxCustomLabel" /> <FileSource src="/framed/ComboBox/FilterableComboBoxCustomLabel" />
## Top direction ## Top direction
Set `direction` to `"top"` for the combobox dropdown menu to appear above the input. Set `direction` to `"top"` to make the dropdown menu appear above the input.
<ComboBox direction="top" titleText="Contact" placeholder="Select contact method" <ComboBox direction="top" titleText="Contact" placeholder="Select contact method"
items={[ items={[
@ -82,6 +96,8 @@ items={[
## Light variant ## Light variant
Set `light` to `true` to use the light color scheme.
<ComboBox light titleText="Contact" placeholder="Select contact method" <ComboBox light titleText="Contact" placeholder="Select contact method"
items={[ items={[
{id: "0", text: "Slack"}, {id: "0", text: "Slack"},
@ -91,6 +107,8 @@ items={[
## Extra-large size ## Extra-large size
Set `size` to `"xl"` for an extra-large combobox.
<ComboBox titleText="Contact" placeholder="Select contact method" <ComboBox titleText="Contact" placeholder="Select contact method"
size="xl" size="xl"
items={[ items={[
@ -101,6 +119,8 @@ items={[
## Small size ## Small size
Set `size` to `"sm"` for a small combobox.
<ComboBox titleText="Contact" placeholder="Select contact method" <ComboBox titleText="Contact" placeholder="Select contact method"
size="sm" size="sm"
items={[ items={[
@ -111,6 +131,8 @@ items={[
## Invalid state ## Invalid state
Set `invalid` to `true` and provide `invalidText` to show an error message.
<ComboBox invalid invalidText="Secondary contact method must be different from the primary contact" titleText="Contact" placeholder="Select contact method" <ComboBox invalid invalidText="Secondary contact method must be different from the primary contact" titleText="Contact" placeholder="Select contact method"
items={[ items={[
{id: "0", text: "Slack"}, {id: "0", text: "Slack"},
@ -120,6 +142,8 @@ items={[
## Warning state ## Warning state
Set `warn` to `true` and provide `warnText` to show a warning message.
<ComboBox warn warnText="This contact method is not associated with your account" titleText="Contact" placeholder="Select contact method" <ComboBox warn warnText="This contact method is not associated with your account" titleText="Contact" placeholder="Select contact method"
items={[ items={[
{id: "0", text: "Slack"}, {id: "0", text: "Slack"},
@ -129,6 +153,8 @@ items={[
## Disabled state ## Disabled state
Set `disabled` to `true` to prevent interaction with the combobox.
<ComboBox disabled titleText="Contact" placeholder="Select contact method" <ComboBox disabled titleText="Contact" placeholder="Select contact method"
items={[ items={[
{id: "0", text: "Slack"}, {id: "0", text: "Slack"},
@ -138,7 +164,7 @@ items={[
## Disabled items ## Disabled items
Use the `disabled` property in the `items` prop to disable specific items. Set `disabled: true` in an item object to disable specific options.
<ComboBox <ComboBox
titleText="Contact" titleText="Contact"