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 * as Ariakit from "@ariakit/react";
import "./style.css";
export default function Example() {
const combobox = Ariakit.useComboboxStore();
return (
<div className="wrapper">
<label className="label">
Your favorite fruit
<Ariakit.Combobox
store={combobox}
placeholder="e.g., Apple"
className="combobox"
/>
</label>
<Ariakit.ComboboxPopover
store={combobox}
gutter={4}
sameWidth
className="popover"
>
<Ariakit.ComboboxItem className="combobox-item" value="Apple">
🍎 Apple
</Ariakit.ComboboxItem>
<Ariakit.ComboboxItem className="combobox-item" value="Grape">
🍇 Grape
</Ariakit.ComboboxItem>
<Ariakit.ComboboxItem className="combobox-item" value="Orange">
🍊 Orange
</Ariakit.ComboboxItem>
<Ariakit.ComboboxItem className="combobox-item" value="Strawberry">
🍓 Strawberry
</Ariakit.ComboboxItem>
<Ariakit.ComboboxItem className="combobox-item" value="Watermelon">
🍉 Watermelon
</Ariakit.ComboboxItem>
</Ariakit.ComboboxPopover>
</div>
);
}

Installation

npm i @ariakit/react

Learn more on the Getting started guide.

API

useComboboxStore()

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

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 on the Styling guide.