Combobox example

Search rich options and submit IDs.

Search labels, descriptions or aliases without using display text as the selected value.

Complete React client module · MIT · Next.js and Vite

Interactive example

Search rich options and submit IDs

Search labels, descriptions or aliases without using display text as the selected value.

Keyboard

  • Type to filter labels, descriptions and search terms.
  • ArrowDown highlights a result; Enter commits its ID.
  • Escape closes the list without discarding the committed selection.

States covered

  • controlled value
  • stable IDs
  • grouped results
  • search aliases
  • custom row
  • native form
  • blur binding

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-combobox-canonical-options.json
Complete source
React / TypeScript
/*!
MIT License

Copyright (c) 2026 Jaison

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
'use client';
import '@bld8/ui/styles.css';
import { useState } from 'react';
import { MapPin } from 'lucide-react';
import { Button, Combobox, type Option } from '@bld8/ui';
const offices: Option[] = [
  { value: 'mel-studio', label: 'Melbourne studio', group: 'Australia', icon: MapPin, description: 'City centre workspace.', searchTerms: ['victoria', 'collingwood'] },
  { value: 'syd-studio', label: 'Sydney studio', group: 'Australia', icon: MapPin, description: 'Harbour workspace.', searchTerms: ['nsw'] },
  { value: 'wlg-studio', label: 'Wellington studio', group: 'New Zealand', icon: MapPin, description: 'Waterfront workspace.', searchTerms: ['aotearoa'] }
];
export default function CanonicalComboboxExample() {
  const [value, setValue] = useState<string | null>('mel-studio');
  const [submitted, setSubmitted] = useState('Not submitted');
  const [touched, setTouched] = useState(false);
  return <form aria-label="Office search example" onSubmit={event => {
    event.preventDefault(); setSubmitted(String(new FormData(event.currentTarget).get('office') ?? ''));
  }} style={{ display: 'grid', gap: 16, maxWidth: 440 }}>
    <Combobox label="Office location" name="office" options={offices} value={value} onValueChange={setValue} clearable
      onBlur={() => setTouched(true)} hint="Try searching for victoria or waterfront."
      renderOption={option => <strong style={{ fontWeight: 500 }}>{option.label}</strong>} />
    <Button type="submit">Read office ID</Button>
    <output aria-label="Office form value">{submitted}</output>
    <p>Office field touched: {touched ? 'yes' : 'no'}</p>
  </form>;
}