Skip to main content
Tw Twintrinsic
  • Getting Started
  • Components
  • Theming
  • Completion
Examples
Data Dashboard Game Map
Core
App
Layout
Accordion AccordionItem Card Container Panel Separator Sidebar Splitter
Navigation
AppHeader BottomBar Breadcrumb BreadcrumbItem Menu MenuItem Tabs Tab TabList TabPanel TreeMenu
Data Display
Avatar AvatarGroup Badge Carousel CarouselItem Chip ChipGroup CodeBlock CodeBlockSpeed CodeEditor DataTable Map Progress Skeleton Table TableBody TableCell TableHead TableHeader TableRow Tag TagGroup Timeline TimelineItem Tooltip Tree TreeNode
Metrics
DonutChart PieChart LineChart BarChart HorizontalBarChart AreaChart StatsCard MetricGrid KPICard GaugeChart ProgressMetric MetricTrend
Form
AutoComplete Button ButtonGroup Calendar Checkbox ColorPicker Combobox Dropdown FileUpload FloatLabel Form FormField Input InputSwitch InvalidState Knob ListInput Listbox NumberInput Radio RadioGroup Rating Select SelectGroup Slider Switch TextInput Textarea
Feedback
Modal Stepper StepperStep Toast
Utility
Icon Lazy LazyPanel Masonry ThemeToggle

Combobox

The Combobox component combines a text input with a dropdown list, providing autocomplete functionality with keyboard navigation and accessibility features. It's ideal for selecting from a large list of options with search capability.

Examples

Basic Combobox

svelte
<Combobox 
  options={['Apple', 'Banana', 'Cherry', 'Date', 'Elderberry']}
  placeholder="Select a fruit"
  onchange={(e) => console.log(e.detail.value)}
/>

With Object Data

svelte
<Combobox 
  options={countries}
  optionLabel="name"
  optionValue="code"
  placeholder="Select a country"
  onchange={(e) => console.log(e.detail.value)}
/>

Custom Option Template

svelte
<Combobox 
  options={countries}
  optionLabel="name"
  optionValue="code"
  placeholder="Select a country"
  let:option
>
  <div class="flex items-center">
    <span class="mr-2 text-lg">{option.flag}</span>
    <span>{option.name}</span>
    <span class="ml-2 text-xs text-muted">({option.code})</span>
  </div>
</Combobox>

Disabled State

svelte
<Combobox 
  options={fruits}
  placeholder="Select a fruit"
  disabled
/>

Loading State

svelte
<Combobox 
  options={[]}
  placeholder="Loading options..."
  loading
/>

With Initial Value

svelte
<Combobox 
  options={fruits}
  placeholder="Select a fruit"
  value="Banana"
/>

Form Integration

svelte
<div>
  <label for="fruit-select" class="block text-sm font-medium mb-1">Favorite Fruit</label>
  <Combobox 
    id="fruit-select"
    name="fruit"
    options={fruits}
    placeholder="Select a fruit"
    required
  />
</div>

Props

PropTypeDefaultDescription
optionsArray[]Options to display in the dropdown
valueanynullCurrent value
placeholderstring"Select an option"Placeholder text
optionLabelstring"label"Property name for option labels
optionValuestring"value"Property name for option values
disabledbooleanfalseWhether the combobox is disabled
readonlybooleanfalseWhether the combobox is readonly
requiredbooleanfalseWhether the combobox is required
searchablebooleantrueWhether to allow searching
clearablebooleantrueWhether to allow clearing the selection
loadingbooleanfalseWhether to show a loading indicator
autoSelectbooleanfalseWhether to automatically select the first option
openOnFocusbooleantrueWhether to open the dropdown on focus
maxHeightnumber250Maximum height of the dropdown in pixels
ariaLabelstringundefinedARIA label for the combobox
filterFunctionundefinedCustom filter function
namestringundefinedName attribute for the input
idstringrandom UUIDHTML id for accessibility
classstring""Additional CSS classes

Events

EventDetailDescription
change{ value: any, option: any }Fired when the selection changes
input{ value: any, option: any }Fired when the input value changes

Slots

SlotPropsDescription
default{ option }Custom template for option items

Accessibility

The Combobox component follows WAI-ARIA guidelines for comboboxes:

  • Uses role="combobox" for the input element
  • Uses role="listbox" for the dropdown
  • Uses role="option" for each option
  • Proper aria-expanded, aria-controls, aria-activedescendant, and aria-selected attributes
  • Supports keyboard navigation
  • Provides proper focus management

Keyboard Support

KeyFunction
TabMoves focus to the combobox
EnterWhen dropdown is open, selects the highlighted option
EscapeCloses the dropdown
ArrowDownOpens the dropdown if closed, or moves highlight to the next option
ArrowUpOpens the dropdown if closed, or moves highlight to the previous option