Ariakit
/
/
This site is under construction Subscribe to updates

Combobox

Fill in a React input field with autocomplete & autosuggest functionalities. Choose from a list of suggested values with full keyboard support. This component is based on the WAI-ARIA Combobox Pattern.

import {
  Combobox,
  ComboboxItem,
  ComboboxPopover,
  useComboboxState,
} from "ariakit/combobox";
import "./style.css";

export default function Example() {
  const combobox = useComboboxState({ gutter: 4, sameWidth: true });
  return (
    <div className="wrapper">
      <label className="label">
        Your favorite fruit
        <Combobox
          state={combobox}
          placeholder="e.g., Apple"
          className="combobox"
        />
      </label>
      <ComboboxPopover state={combobox} className="popover">
        <ComboboxItem className="combobox-item" value="Apple">
          🍎 Apple
        </ComboboxItem>
        <ComboboxItem className="combobox-item" value="Grape">
          🍇 Grape
        </ComboboxItem>
        <ComboboxItem className="combobox-item" value="Orange">
          🍊 Orange
        </ComboboxItem>
        <ComboboxItem className="combobox-item" value="Strawberry">
          🍓 Strawberry
        </ComboboxItem>
        <ComboboxItem className="combobox-item" value="Watermelon">
          🍉 Watermelon
        </ComboboxItem>
      </ComboboxPopover>
    </div>
  );
}

Installation

npm install ariakit

Learn more in Getting started.

API

useComboboxState()

<Combobox />
<ComboboxCancel />
<ComboboxDisclosure />
<ComboboxList|ComboboxPopover>
  <ComboboxGroup>
    <ComboboxGroupLabel />
    <ComboboxRow>
      <ComboboxItem>
        <ComboboxItemValue />
      </ComboboxItem>
      <ComboboxSeparator />
    </ComboboxRow>
  </ComboboxGroup>
</ComboboxList|ComboboxPopover>

Styling

Styling the active item

When browsing the list with a keyboard (or hovering over items with the mouse when the focusOnHover prop is true), the active item element will have a data-active-item attribute. You can use this attribute to style the active item:

.combobox-item[data-active-item] {
  background-color: hsl(204 100% 40%);
  color: white;
}

Learn more in Styling.