coss.com Svelte

Combobox

An input combined with a list of predefined items to select.

API Reference
Loading p-combobox-1 preview…

Installation

pnpm dlx shadcn-svelte@latest add https://coss-sv.vercel.app/r/combobox.json

Usage

Single Selection

<script lang="ts">
  import * as Combobox from "$lib/components/ui/combobox/index.js";
</script>
<script lang="ts">
  const items = [
    { value: "apple", label: "Apple" },
    { value: "banana", label: "Banana" },
    { value: "orange", label: "Orange" },
    { value: "grape", label: "Grape" },
  ];
</script>

<Combobox.Root {items}>
  <Combobox.Input placeholder="Select an item..." />
  <Combobox.Popup>
    <Combobox.Empty>No results found.</Combobox.Empty>
    <Combobox.List>
      <Combobox.Collection>
        {#snippet children(item)}
          <Combobox.Item value={item}>{item.label}</Combobox.Item>
        {/snippet}
      </Combobox.Collection>
    </Combobox.List>
  </Combobox.Popup>
</Combobox.Root>

Multiple Selection

<script lang="ts">
  import * as Combobox from "$lib/components/ui/combobox/index.js";
</script>
<script lang="ts">
  const items = [
    { value: "apple", label: "Apple" },
    { value: "banana", label: "Banana" },
    { value: "orange", label: "Orange" },
    { value: "grape", label: "Grape" },
  ] as const;
  type Item = (typeof items)[number];
</script>

<Combobox.Root {items} multiple>
  <Combobox.Chips>
    <Combobox.Value>
      {#snippet children(value: Item[])}
        {#each value as item (item.value)}
          <Combobox.Chip aria-label={item.value} value={item.value}>
            {item.label}
          </Combobox.Chip>
        {/each}
        <Combobox.ChipsInput
          aria-label="Select an item"
          placeholder={value.length > 0 ? undefined : "Select an item..."}
        />
      {/snippet}
    </Combobox.Value>
  </Combobox.Chips>
  <Combobox.Popup>
    <Combobox.Empty>No results found.</Combobox.Empty>
    <Combobox.List>
      <Combobox.Collection>
        {#snippet children(item: Item)}
          <Combobox.Item value={item}>{item.label}</Combobox.Item>
        {/snippet}
      </Combobox.Collection>
    </Combobox.List>
  </Combobox.Popup>
</Combobox.Root>

API Reference

Combobox.Root

The root combobox component. Manages the combobox state and provides context to child components.

PropTypeDescription
itemsreadonly unknown[]The array of items to display in the combobox
multiplebooleanWhether to allow multiple selection
openbooleanControls whether the popup is open
childrenSnippetCombobox content
...propsComboboxRootPropsAll Shards UI Combobox props are supported

Combobox.Input

The input field component for single selection mode with extended features for size variants and addon support.

PropTypeDefaultDescription
size"sm" \| "default" \| "lg""default"The size variant of the input field
startAddonSnippet-Content to display at the start of the input, such as an icon
showTriggerbooleantrueWhether to display a trigger button on the right side of the input
showClearbooleanfalseWhether to display a clear button on the right side of the input when there is a value
triggerPropsComboboxTriggerProps-Props forwarded to the internal trigger button, useful for overriding aria-label
clearPropsComboboxClearProps-Props forwarded to the internal clear button, useful for overriding aria-label
classstring-Additional CSS classes to apply to the component
...propsComboboxInputProps-All standard combobox input attributes are supported

Combobox.Popup

The popup container that displays the combobox options.

PropTypeDescription
classstringAdditional CSS classes to apply to the component
portalPropsComboboxPopupProps["portalProps"]Props forwarded to the internal portal
...propsComboboxPopupPropsAll standard combobox popup attributes are supported

Combobox.List

A scrollable container for combobox items.

PropTypeDescription
classstringAdditional CSS classes to apply to the component
childrenSnippetList content
...propsComboboxListPropsAll standard combobox list attributes are supported

Combobox.Item

An individual selectable combobox item.

PropTypeDescription
valueunknownThe value of the item
classstringAdditional CSS classes to apply to the component
childrenSnippetItem content
...propsComboboxItemPropsAll standard combobox item attributes are supported

Combobox.Empty

Displays a message when no results are found.

PropTypeDescription
classstringAdditional CSS classes to apply to the component
childrenSnippetEmpty-state content
...propsComboboxEmptyPropsAll standard combobox empty attributes are supported

Combobox.Group

Groups related combobox items together.

PropTypeDescription
itemsreadonly unknown[]The array of items in this group
classstringAdditional CSS classes to apply to the component
childrenSnippetGroup content
...propsComboboxGroupPropsAll standard combobox group attributes are supported

Combobox.GroupLabel

Displays a label for a combobox group.

PropTypeDescription
classstringAdditional CSS classes to apply to the component
childrenSnippetLabel content
...propsComboboxGroupLabelPropsAll standard combobox group label attributes are supported

Combobox.Collection

Used to wrap items within a group for rendering.

PropTypeDescription
childrenSnippet<[unknown]>Renders each filtered item
...propsComponentProps<typeof Combobox.Collection>All standard combobox collection attributes are supported

Combobox.Chips

Container for displaying selected chips in multiple selection mode.

PropTypeDescription
startAddonSnippetContent to display at the start of the chips area
classstringAdditional CSS classes to apply to the component
childrenSnippetChips content
...propsComboboxChipsPropsAll standard div attributes are supported

Combobox.ChipsInput

The input field component for use inside Combobox.Chips in multiple selection mode. This is a minimal input without the wrapper, trigger, or clear button.

PropTypeDefaultDescription
size"sm" \| "default" \| "lg""default"The size variant of the input field
classstring-Additional CSS classes to apply to the component
...propsComboboxChipsInputProps-All standard combobox input attributes are supported

Combobox.Chip

An individual chip representing a selected item in multiple selection mode.

PropTypeDescription
removePropsComboboxChipRemovePropsProps forwarded to the internal remove button, useful for overriding aria-label
classstringAdditional CSS classes to apply to the component
childrenSnippetChip content
...propsComboboxChipPropsAll standard combobox chip attributes are supported

Combobox.Value

Provides access to the current value for custom rendering.

PropTypeDescription
childrenSnippet<[unknown]>Receives the current combobox value
...propsComboboxValuePropsAll standard combobox value attributes are supported

Examples

Disabled

Loading p-combobox-2 preview…

Small Size

Loading p-combobox-3 preview…

Large Size

Loading p-combobox-4 preview…

With Label

Loading p-combobox-5 preview…

Auto Highlight

Automatically highlight the first matching option.

Loading p-combobox-6 preview…

With Clear Button

Loading p-combobox-7 preview…

With Groups

Loading p-combobox-8 preview…

With Multiple Selection

Loading p-combobox-9 preview…

With Start Addon

Display an icon or other element at the start of the input using the startAddon prop.

Loading p-combobox-13 preview…

With Start Addon - Multiple

Use the startAddon prop on Combobox.Chips to display an icon at the start when using multiple selection.

Loading p-combobox-14 preview…

With Input Inside Popup

Loading p-combobox-10 preview…

With Select-like Button

Use selectTriggerClass on Combobox.Trigger to make the combobox trigger look like a select.

Loading p-combobox-18 preview…

Form Integration

Loading p-combobox-11 preview…

Form Integration - Multiple

Loading p-combobox-12 preview…