HextaUI

Combobox: Clear button

showClear adds a clear button that takes the chevron’s place while there is a value, so the field never grows.

"use client"

import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
} from "@/components/ui/combobox"
import { Label } from "@/components/ui/label"

const fruits = [
  "Apple",
  "Apricot",
  "Banana",
  "Blackberry",
  "Blueberry",
  "Cherry",
  "Grape",
  "Grapefruit",
  "Kiwi",
  "Lychee",
  "Mango",
  "Orange",
  "Papaya",
  "Peach",
  "Pear",
  "Pineapple",
  "Plum",
  "Raspberry",
  "Strawberry",
  "Watermelon",
]

export function ComboboxWithClear() {
  return (
    <div className="flex w-full max-w-xs flex-col gap-2">
      <Label htmlFor="combobox-clear">Fruit</Label>
      <Combobox items={fruits} defaultValue="Mango">
        <ComboboxInput
          id="combobox-clear"
          placeholder="Select a fruit"
          showClear
        />
        <ComboboxContent>
          <ComboboxEmpty>No fruit found.</ComboboxEmpty>
          <ComboboxList>
            {(item: string) => (
              <ComboboxItem key={item} value={item}>
                {item}
              </ComboboxItem>
            )}
          </ComboboxList>
        </ComboboxContent>
      </Combobox>
    </div>
  )
}

This adds the example as components/examples/combobox/clear.tsx, together with the Combobox component and the HextaUI theme tokens it needs.

pnpm dlx shadcn@latest add https://hextaui.com/r/combobox-clear.json

To add only the component, follow the Combobox installation.

Props in this example

The Combobox props this example sets, from the API reference.

PropTypeDefault
itemsThe options. Filtered as you type and passed to the list’s render function.
Item[] | Group[]–
defaultValue
Value | Value[] | null–
PropTypeDefault
showClearShow a clear button in the chevron’s place while there is a value.
booleanfalse
placeholder
string–
PropTypeDefault
valueThe item this row represents.
Item–

Every prop is in the Combobox API reference.

See them all, with keyboard support and accessibility notes, on the Combobox page.