Select example

Grouped choices with stable values.

Icons and descriptions explain each choice while forms keep the canonical ID.

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

Interactive example

Grouped choices with stable values

Icons and descriptions explain each choice while forms keep the canonical ID.

Keyboard

  • Open the list with Enter or Space.
  • Arrow keys move between enabled choices; type a label for typeahead.
  • Enter selects; Escape closes and returns focus to the trigger.

States covered

  • controlled value
  • controlled popup
  • groups
  • icons
  • descriptions
  • disabled option
  • native form
  • clearable

Install this complete example and its component dependencies.

Terminal
npx shadcn@latest add https://ui.bld8.dev/r/example-select-rich-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 { useRef, useState } from 'react';
import { Archive, Cloud, Server } from 'lucide-react';
import { Button, Select, type Option } from '@bld8/ui';

const targets: Option[] = [
  { value: 'cluster-preview', label: 'Preview cluster', group: 'Delivery', icon: Cloud, description: 'Quick checks before a release.' },
  { value: 'cluster-primary', label: 'Primary cluster', group: 'Delivery', icon: Server, description: 'The production destination.' },
  { value: 'cluster-archive', label: 'Archive cluster', group: 'History', icon: Archive, description: 'Kept for existing deployments.', disabled: true }

];
export default function GroupedSelectExample() {
  const [value, setValue] = useState<string | null>('cluster-preview');
  const [open, setOpen] = useState(false);
  const [submitted, setSubmitted] = useState('Not submitted');
  const trigger = useRef<HTMLButtonElement>(null);
  return <form aria-label="Deployment selection example" onSubmit={event => {
    event.preventDefault(); setSubmitted(String(new FormData(event.currentTarget).get('deployment') ?? ''));
  }} style={{ display: 'grid', gap: 16, maxWidth: 440 }}>
    <Select label="Deployment target" name="deployment" options={targets} value={value} onValueChange={setValue}
      open={open} onOpenChange={setOpen} inputRef={trigger} clearable hint="The submitted value is a cluster ID." />
    <div style={{ display: 'flex', gap: 8, flexWrap: 'wrap' }}>
      <Button variant="secondary" onClick={() => { trigger.current?.focus(); setOpen(true); }}>Open target list</Button>
      <Button type="submit">Read deployment value</Button>
    </div>
    <output aria-label="Deployment form value">{submitted}</output>
  </form>;
}