Skip to main content
PROYECTOVIVIANA

ComboBox

A combination of a text input and a dropdown listbox. Users can type to filter the options and select from the filtered list. Fully keyboard accessible.

Import

import {
  ComboBox,
  ComboBoxOption,
  defaultContainsFilter,
} from '@proyecto-viviana/solid-spectrum';

Basic with Filtering

Type to filter the list. Press Enter or click to select.

Selected: none

<ComboBox
  items={foods}
  getKey={(item) => item.id}
  getTextValue={(item) => item.name}
  selectedKey={selected()}
  onSelectionChange={setSelected}
  defaultFilter={defaultContainsFilter}
  label="Select a food"
  placeholder="Type to filter..."
>
  {(item) => <ComboBoxOption id={item.id}>{item.name}</ComboBoxOption>}
</ComboBox>

Sizes

Three size variants for different contexts.

<ComboBox items={foods} size="sm" label="Small" placeholder="Filter..." ...>
<ComboBox items={foods} size="md" label="Medium" placeholder="Filter..." ...>
<ComboBox items={foods} size="lg" label="Large" placeholder="Filter..." ...>

With Description & Validation

Helper text and validation error support.

Choose your favorite food
Please select a valid food item
<ComboBox
  label="Required Food"
  isInvalid
  errorMessage="Please select a food item"
  ...
/>

Disabled

A disabled ComboBox cannot be opened or typed in.

<ComboBox isDisabled defaultSelectedKey="apple" label="Disabled" ...>

Props

PropTypeDefaultDescription
itemsT[]Array of items to display
getKey(item: T) => string | numberExtracts the unique key from an item
getTextValue(item: T) => stringExtracts the display text for filtering
selectedKeystring | number | nullControlled selected key
defaultSelectedKeystring | numberUncontrolled default selection
onSelectionChange(key: string | number | null) => voidCalled when selection changes
defaultFilter(item: T, inputValue: string) => booleanFilter function for typing (use defaultContainsFilter)
labelstringVisible label
placeholderstringInput placeholder
size'sm' | 'md' | 'lg''md'Size variant
isDisabledbooleanfalsePrevents interaction
isInvalidbooleanfalseShows error styling
errorMessagestringValidation error message
descriptionstringHelper text

Accessibility

  • Uses combobox ARIA role with aria-expanded and aria-haspopup
  • Arrow keys navigate the list; Enter/Space select; Escape closes
  • Active option communicated via aria-activedescendant
  • Supports type-ahead filtering natively via defaultFilter