webflow svelte components logoWFS

Combobox

A customizable dropdown component that allows users to select an item from a list, with support for filtering and custom styling.

API Reference

Usage

<script lang="ts">
  import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '$lib/components/combobox';
 
  const roles = [
    { value: 'admin', label: 'Admin' },
    { value: 'editor', label: 'Editor' },
    { value: 'reviewer', label: 'Reviewer' },
    { value: 'guest', label: 'Guest' }
  ];
 
  let inputValue = '';
  let touchedInput = false;
 
  $: filteredRoles = inputValue && touchedInput ? roles.filter((role) => role.label.toLowerCase().includes(inputValue.toLowerCase())) : roles;
</script>
<Combobox items={filteredRoles} bind:inputValue bind:touchedInput>
  <ComboboxInput placeholder="Assign user roles" />
  <ComboboxContent>
    {#each filteredRoles as role (role.value)}
      <ComboboxItem value={role.value} label={role.label}>
        {role.label}
      </ComboboxItem>
    {:else}
      <span>No roles found</span>
    {/each}
  </ComboboxContent>
</Combobox>

Properties

The Combobox component extends the Bits UI <Combobox> component. Find the full list of available properties in the official Bits UI documentation.

ComboboxInput

PropTypeDefault
icon
ComponentType
-

ComboboxItem

PropTypeDefault
icon
ComponentType
-

Examples

Use the ComboboxHeader component to add a header to the combobox.

Icon support

Use the icon property to add an icon to either the ComboboxInput or ComboboxItem component.

Description

Use the Description component inside the ComboboxItem component to provide additional information about the combobox item.

Sublabel

Use the Sublabel component inside the ComboboxItem component to add a secondary label to the combobox item.

Disabled

Use the disabled property to prevent users from interacting with the combobox.

Disabled item

Use the disabled property inside the ComboboxItem component to prevent users from interacting with the combobox item.

On this page