PeakUI

ComboBox

Text input with a filterable list of options

Usage

import {ComboBox, Input, Label, ListBox} from "@peakui/react";

Anatomy

import {ComboBox, Description, FieldError, Input, Label, ListBox} from "@peakui/react";

export default () => (
  <ComboBox>
    <Label />
    <ComboBox.InputGroup>
      <Input />
      <ComboBox.Trigger />
    </ComboBox.InputGroup>
    <ComboBox.Value />
    <Description />
    <FieldError />
    <ComboBox.Popover>
      <ListBox>
        <ListBox.Item>
          <ListBox.ItemIndicator />
        </ListBox.Item>
      </ListBox>
    </ComboBox.Popover>
  </ComboBox>
);

Examples

Variants

Full Width

Default Selected Key

With Description

With Sections

With Disabled Options

Custom Indicator

Required

Dynamic Items

Custom Filtering

Allows Custom Value

Multiple Selection

Multiple Selection With Chips

Controlled

Controlled Input Value

Controlled Multiple Selection

Disabled

Customization

Tailwind CSS

Global CSS

@layer components {
  .combo-box {
    @apply flex flex-col gap-1;
  }

  .combo-box__trigger {
    @apply text-muted;
  }

  .combo-box__popover {
    @apply rounded-lg border border-border bg-surface p-2;
  }
}

Styling Reference

PeakUI follows the BEM methodology, so variants and states are plain class names you can target.

CSS Classes

The ComboBox component uses these CSS classes (view source styles):

Base & Element Classes

  • .combo-box - Base combo box container
  • .combo-box__input-group - Wraps the input and the trigger
  • .combo-box__trigger - The button that opens the list
  • .combo-box__value - The selected items in multiple selection
  • .combo-box__popover - The popover container

Modifier Classes

  • .combo-box--full-width - Takes the full width of the container
  • .combo-box__input-group--full-width - Full width on the input group itself

The field surface comes from Input: variant reaches it through the root, so it styles .input--primary and .input--secondary.

Slots

  • [data-slot="combo-box"]
  • [data-slot="combo-box-input-group"]
  • [data-slot="combo-box-trigger"]
  • [data-slot="combo-box-trigger-default-icon"]
  • [data-slot="combo-box-value"]
  • [data-slot="combo-box-popover"]

Interactive States

The component supports both CSS pseudo-classes and data attributes:

  • Hover: :hover or [data-hovered] on trigger
  • Focus: :focus-visible or [data-focus-visible] on trigger
  • Pressed: :active or [data-pressed] on trigger
  • Disabled: :disabled, [data-disabled] or [aria-disabled="true"] on trigger
  • Invalid: [data-invalid] or [aria-invalid="true"] on combo box
  • Placeholder: [data-placeholder] on value
  • Open: [data-open] on trigger

API Reference

ComboBox

PropTypeDefaultDescription
selectionMode"single" | "multiple""single"Whether single or multiple selection is enabled
selectedKeyKey | null-Selected key (controlled), single selection
defaultSelectedKeyKey | null-Selected key (uncontrolled), single selection
onSelectionChange(key: Key | null) => void-Handler called when the selected key changes, single selection
valueKey[]-Selected keys (controlled), multiple selection
defaultValueKey[]-Selected keys (uncontrolled), multiple selection
onChange(value: Key[]) => void-Handler called when the selected keys change, multiple selection
inputValuestring-Text in the input (controlled)
defaultInputValuestring-Text in the input (uncontrolled)
onInputChange(value: string) => void-Handler called when the input text changes
defaultItemsIterable<T>-Items for a dynamic collection, filtered by the combo box
itemsIterable<T>-Items for a dynamic collection, filtered by the consumer
defaultFilter(textValue: string, inputValue: string) => booleancontainsDecides whether an option stays in the list
menuTrigger"focus" | "input" | "manual""focus"What opens the list: focusing the input, typing, or only the trigger and arrow keys
allowsCustomValuebooleanfalseWhether text that matches no option is kept
allowsEmptyCollectionbooleanfalseWhether the list may stay open when no option matches
isOpenboolean-Sets the open state of the list (controlled)
defaultOpenboolean-Sets the default open state of the list (uncontrolled)
onOpenChange(isOpen: boolean) => void-Handler called when the open state changes
disabledKeysIterable<Key>-Keys of disabled items
isDisabledboolean-Whether the combo box is disabled
isReadOnlyboolean-Whether the input can be edited
isRequiredboolean-Whether user input is required
isInvalidboolean-Whether the value is invalid
namestring-The name of the input, used when submitting an HTML form
formValue"text" | "key""key"Whether the text or the key is submitted; allowsCustomValue always submits the text
fullWidthbooleanfalseWhether the combo box takes the full width of its container
variant"primary" | "secondary""primary"Visual variant of the field; secondary is the lower emphasis variant for surfaces
classNamestring | (values: ComboBoxRenderProps) => string-Additional classes, or a function of the render props
childrenReactNode | (values: ComboBoxRenderProps) => ReactNode-Combo box content, or a function of the render props
...restEvery React Aria ComboBox attribute is accepted, including aria-label

ComboBox.InputGroup

PropTypeDefaultDescription
classNamestring | (values: GroupRenderProps) => string-Additional classes, or a function of the render props
childrenReactNode | (values: GroupRenderProps) => ReactNode-The Input and the ComboBox.Trigger
...restEvery React Aria Group attribute is accepted

ComboBox.Trigger

Without children it renders a chevron; its aria-label defaults to the localized "Show suggestions".

PropTypeDefaultDescription
classNamestring | (values: ButtonRenderProps) => string-Additional classes, or a function of the render props
childrenReactNode | (values: ButtonRenderProps) => ReactNode-Custom indicator, replacing the default chevron
...restEvery React Aria Button attribute is accepted

ComboBox.Value

Shows the selected items in multiple selection, where the input holds only the search text.

PropTypeDefaultDescription
placeholderstring-Text shown while nothing is selected
classNamestring | (values: ComboBoxValueRenderProps<T>) => string-Additional classes, or a function of the render props
childrenReactNode | (values: ComboBoxValueRenderProps<T>) => ReactNode-Value content, or a function of the render props
...restEvery <div> attribute is accepted

ComboBox.Popover

PropTypeDefaultDescription
placement"bottom" | "bottom left" | "bottom right" | "bottom start" | "bottom end" | "top" | "top left" | "top right" | "top start" | "top end" | "left" | "left top" | "left bottom" | "start" | "start top" | "start bottom" | "right" | "right top" | "right bottom" | "end" | "end top" | "end bottom""bottom"Placement of the popover relative to the field
classNamestring-Additional classes
childrenReactNode-Content children
...restEvery React Aria Popover attribute is accepted

Render Props

ComboBox children and className functions receive ComboBoxRenderProps; ComboBox.Value functions receive these values:

PropTypeDescription
isPlaceholderbooleanWhether the value is a placeholder
selectedItems(T | null)[]The currently selected items
selectedTextstringThe text of the selected items
stateComboBoxState<T, M>The state of the combo box

On this page