Combobox
An autocomplete input that combines a text input with a dropdown list of suggestions.
Anatomy
<script>
import {
Combobox,
ComboboxControl,
ComboboxInput,
ComboboxTrigger,
ComboboxClearTrigger,
ComboboxContent,
ComboboxItem,
ComboboxItemText,
ComboboxItemIndicator,
ComboboxItemGroup,
ComboboxItemGroupLabel,
ComboboxEmpty,
} from "@saas-ui/svelte/components/combobox";
</script>
<Combobox.Root items={items}>
<Combobox.Label>Select Item</Combobox.Label>
<Combobox.Control>
<Combobox.Input placeholder="Search..." />
<Combobox.IndicatorGroup>
<Combobox.ClearTrigger />
<Combobox.Trigger />
</Combobox.IndicatorGroup>
</Combobox.Control>
<Combobox.Content>
<Combobox.Empty>No results found</Combobox.Empty>
{#each items as item}
<Combobox.Item item={item}>
<Combobox.ItemText>{item.label}</Combobox.ItemText>
<Combobox.ItemIndicator />
</Combobox.Item>
{/each}
</Combobox.Content>
</Combobox.Root>Examples
Allow Custom Value Accessibility
allowCustomValue prop to allow custom values.
<VStack gap={4} class="w-80">
<HStack gap={2} class="text-sm">
<Text as="span">Value:</Text>
{#if customValue.length> 0}
<HStack gap={1}>
{#each customValue as v}<Badge>{v}</Badge>{/each}
</HStack> Async Loading Accessibility
{@const items = asyncItems.map((c) => ({
label: c.name,
value: c.name,
description: `${c.height}cm / ${c.mass}kg`,
}))}
<Combobox
{items}
label="Search Star Wars Characters"
placeholder="Type to search"
loading={isLoading}
loadingText="Loading..."
emptyText="No characters found"
openOnClick
disableFilter
itemDescriptionKey="description"
onInputValueChange={(e) => handleAsyncInputChange(e.inputValue)}
class="w-80"
/> Basic Accessibility
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type to search"
class="w-80"
/> Colours Accessibility
colour prop to change the colour scheme.
<VStack gap={8} class="w-80">
{#each comboboxColours as colour}
<Combobox
items={frameworks}
label="Colour: {colour}"
placeholder="Type to search"
{colour}
/>
{/each}
</VStack> Controlled Open Accessibility
<VStack gap={4} class="w-80">
<HStack gap={2}>
<Button size="sm" onclick={() => (isOpen = !isOpen)}
>{isOpen ? "Close" : "Open"} Combobox</Button>
<Text as="span" size="sm" class="text-fg-muted">Open: {isOpen}</Text>
</HStack>
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type to search"
bind:open={isOpen}
/>
</VStack> Controlled Value Accessibility
<VStack gap={4} class="w-80">
<HStack gap={2} class="text-sm">
<Text as="span">Selected:</Text>
{#if controlledValue.length> 0}
<HStack gap={1}>
{#each controlledValue as v}<Badge>{v}</Badge>{/each}
</HStack> Custom Filter Accessibility
{@const filteredPeople = customFilterPeople(customFilterInput)}
<VStack gap={2} class="w-80">
<Combobox
items={filteredPeople}
label="Search People"
placeholder="Search by name, email, or role..."
disableFilter
openOnClick
itemDescriptionKey="email"
onInputValueChange={(e) => (customFilterInput = e.inputValue)}
/>
<p class="text-fg-muted text-xs">
Try searching "developer" or "example.com"
</p>
</VStack> Custom Objects Accessibility
<Combobox
items={countries}
label="Select country"
placeholder="Type to search"
itemPrefixKey="flag"
limit={10}
openOnClick
class="w-80"
/> Disabled Accessibility
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type to search"
disabled
class="w-80"
/> Disabled Item Accessibility
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type to search"
isItemDisabled={(item) =>
item.value === "angular" || item.value === "ember"}
class="w-80"
/> Field Accessibility
Field component.
<Field.Root class="w-80">
<Field.Label>Framework</Field.Label>
<Combobox items={frameworks} placeholder="Type to search" />
<Field.HelperText>The framework you love to use</Field.HelperText>
</Field.Root> Highlight Match Accessibility
highlightMatch prop to highlight matching text.
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type to search"
highlightMatch
class="w-80"
/> In Popover Accessibility
Popover.
<Popover.Root>
<Popover.Trigger triggerText="Select framework" />
<Popover.Content>
<Popover.Header>
<Popover.Title>Select framework</Popover.Title>
</Popover.Header>
<Popover.Body>
<Combobox
items={frameworks}
placeholder="Type to search"
openOnClick
/>
</Popover.Body>
</Popover.Content>
</Popover.Root> Invalid Accessibility
invalid prop to display validation error styling.
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type to search"
invalid
class="w-80"
/> Limit Accessibility
limit prop to limit the number of items shown.
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type to search"
limit={5}
class="w-80"
/> Links Accessibility
<Combobox
items={linkItems}
label="Select framework"
placeholder="Search frameworks..."
openOnClick
class="w-80"
/> Min Characters Accessibility
minCharacters prop to require minimum characters.
<Combobox
items={frameworks}
label="Select framework"
placeholder="Type at least 2 characters"
minCharacters={2}
class="w-80"
/> Multiple Accessibility
multiple prop to allow selecting multiple items.
<VStack gap={1.5} class="w-80">
{#if selectedSkills.length> 0}
<HStack gap={2} class="flex-wrap">
{#each selectedSkills as skill}
<Badge>{skills.find((s) => s.value === skill)?.label ??
skill}</Badge>
{/each}
</HStack> Open On Click Accessibility
openOnClick prop to open the dropdown on click.
<Combobox
items={frameworks}
label="Select framework"
placeholder="Click to open"
openOnClick
class="w-80"
/> Sizes Accessibility
size prop to change the size of the combobox. Available sizes: xs, sm, md, lg.
<VStack gap={8} class="w-80">
{#each comboboxSizes as size}
<Combobox
items={frameworks}
label="Size: {size}"
placeholder="Type to search"
{size}
/>
{/each}
</VStack> Start Icon Accessibility
startIcon prop to display an icon at the start of the input.
Variants Accessibility
variant prop to change the visual style. Available variants: outline, subtle, flushed.
<VStack gap={8} class="w-80">
{#each comboboxVariants as variant}
<Combobox
items={frameworks}
label="Variant: {variant}"
placeholder="Type to search"
{variant}
/>
{/each}
</VStack> Virtualised Accessibility
virtualised prop for better performance with large lists.
<Combobox
items={countries}
label="Select country"
placeholder="Type to search"
itemPrefixKey="flag"
virtualised
limit={10}
openOnClick
class="w-80"
/>Props
Combobox.Root
The root container component for the combobox.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The combobox content. |
collection | ListCollection<CollectionItem> | - | The collection of items to display. |
id | string | - | The unique identifier for the combobox. If not provided, a unique ID will be auto-generated. |
size | "xs" | "sm" | "md" | "lg" | "md" | The size of the combobox. |
variant | "outline" | "subtle" | "flushed" | "outline" | The visual variant of the combobox input. |
invalid | boolean | false | Whether the combobox is in an invalid state. |
colour | ColourName | "gray" | The colour palette for highlighted items. |
class | string | - | Additional CSS classes to apply. |
Combobox.Label
A label for the combobox component.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The label content. |
class | string | - | Additional CSS classes to apply. |
Combobox.Control
The control container that wraps the input and indicators.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The control content (input, indicators, etc.). |
class | string | - | Additional CSS classes to apply. |
Combobox.Input
The text input field for the combobox.
| Prop | Type | Default | Description |
|---|---|---|---|
placeholder | string | - | Placeholder text for the input. |
class | string | - | Additional CSS classes to apply. |
Combobox.IndicatorGroup
A container for grouping the clear trigger and dropdown trigger.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The indicators (clear trigger, dropdown trigger, etc.). |
class | string | - | Additional CSS classes to apply. |
Combobox.Trigger
The trigger button that opens the combobox dropdown.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | - | Additional CSS classes to apply. |
Combobox.ClearTrigger
A button to clear the current selection.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | - | Additional CSS classes to apply. |
Combobox.Content
The dropdown content container for combobox items.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The dropdown content. |
class | string | - | Additional CSS classes to apply. |
Combobox.Item
An individual selectable item in the dropdown.
| Prop | Type | Default | Description |
|---|---|---|---|
item | CollectionItem | - | The item data object. |
children | Snippet | - | The item content. |
class | string | - | Additional CSS classes to apply. |
Combobox.ItemText
The text content of a combobox item.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The item text content. |
class | string | - | Additional CSS classes to apply. |
Combobox.ItemIndicator
The check indicator shown when an item is selected.
| Prop | Type | Default | Description |
|---|---|---|---|
class | string | - | Additional CSS classes to apply. |
Combobox.ItemGroup
A group of related combobox items with an optional label.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The group content. |
class | string | - | Additional CSS classes to apply. |
Combobox.ItemGroupLabel
A label for a group of combobox items.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The group label content. |
class | string | - | Additional CSS classes to apply. |
Combobox.Empty
Content displayed when no items match the filter.
| Prop | Type | Default | Description |
|---|---|---|---|
children | Snippet | - | The empty state content. |
class | string | - | Additional CSS classes to apply. |