HextaUI

Combobox: Trigger rendered as a Button

Pass render to the trigger to use any button. The popup anchors to it and keeps at least its width.

"use client"

import { Button } from "@/components/ui/button"
import {
  Combobox,
  ComboboxContent,
  ComboboxEmpty,
  ComboboxInput,
  ComboboxItem,
  ComboboxList,
  ComboboxTrigger,
  ComboboxValue,
} from "@/components/ui/combobox"

const countries = [
  { value: "ar", label: "Argentina" },
  { value: "au", label: "Australia" },
  { value: "br", label: "Brazil" },
  { value: "ca", label: "Canada" },
  { value: "de", label: "Germany" },
  { value: "fr", label: "France" },
  { value: "in", label: "India" },
  { value: "jp", label: "Japan" },
  { value: "mx", label: "Mexico" },
  { value: "nl", label: "Netherlands" },
  { value: "uk", label: "United Kingdom" },
  { value: "us", label: "United States" },
]

export function ComboboxButtonTrigger() {
  return (
    <Combobox items={countries} defaultValue={countries[6]}>
      <ComboboxTrigger
        aria-label="Country"
        render={<Button variant="outline" />}
      >
        <ComboboxValue />
      </ComboboxTrigger>
      <ComboboxContent>
        <ComboboxInput placeholder="Search countries" />
        <ComboboxEmpty>No country found.</ComboboxEmpty>
        <ComboboxList>
          {(item: (typeof countries)[number]) => (
            <ComboboxItem key={item.value} value={item}>
              {item.label}
            </ComboboxItem>
          )}
        </ComboboxList>
      </ComboboxContent>
    </Combobox>
  )
}

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

pnpm dlx shadcn@latest add https://hextaui.com/r/combobox-button-trigger.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
placeholder
string–
PropTypeDefault
renderWhen set, the built-in field styles are skipped.
ReactElement | (props, state) => ReactElement<button>
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.