Autocomplete example

Grouped destinations with rich suggestions.

Stable IDs identify suggestions; readable labels become the actual text value. Description and alias search can find destinations, while custom places remain valid free text.

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

Interactive example

Grouped destinations with rich suggestions

Stable IDs identify suggestions; readable labels become the actual text value. Description and alias search can find destinations, while custom places remain valid free text.

Keyboard

  • Open the field and use arrow keys to move through enabled destinations across groups.
  • Enter inserts the city label, never the suggestion ID.
  • Escape keeps the current text and Tab moves to the next control.

States covered

  • Grouped results
  • Rich descriptions
  • Aliases
  • Disabled suggestion
  • Custom destination

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-autocomplete-groups.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 {Autocomplete,type AutocompleteOption} from '@bld8/ui/autocomplete';
const destinations:AutocompleteOption[]=[
  {id:'syd',label:'Sydney',group:'Australia',description:'New South Wales · SYD',searchTerms:['harbour','NSW']},
  {id:'mel',label:'Melbourne',group:'Australia',description:'Victoria · MEL',searchTerms:['VIC']},
  {id:'sin',label:'Singapore',group:'Asia Pacific',description:'Singapore · SIN'},
  {id:'tyo',label:'Tokyo',group:'Asia Pacific',description:'Japan · TYO · unavailable in this example',disabled:true}
];
export default function GroupedDestinationExample(){
  const [destination,setDestination]=useState('');
  return <div style={{display:'grid',gap:12}}>
    <Autocomplete label="Destination" options={destinations} value={destination} onValueChange={setDestination} placeholder="Search city, region or airport code" hint="Choose a suggested city or enter another destination." renderOption={option=><span style={{display:'flex',alignItems:'baseline',justifyContent:'space-between',gap:12}}><span>{option.label}</span><small style={{fontSize:11,fontWeight:400}}>{option.id.toUpperCase()}</small></span>}/>
    <p role="status" aria-label="Destination text">Destination text: {destination||'none'}</p>
  </div>;
}