Combobox
A text input that filters a list of options as the reader types, and commits one of them as the value.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const CUSTOMERS = [ { id: 'brightline', name: 'Brightline Studio' }, { id: 'harbor-pine', name: 'Harbor & Pine' }, { id: 'northgate', name: 'Northgate Labs' }, { id: 'quill', name: 'Quill & Co.' }, { id: 'solstice', name: 'Solstice Outdoor' }, { id: 'verde', name: 'Verde Kitchen' }, { id: 'atlas', name: 'Atlas Freight' }, { id: 'juniper', name: 'Juniper Health' },];export default function ComboboxBasic() { return ( <Field> <FieldLabel>Customer</FieldLabel> <Combobox> <ComboboxInput placeholder="Search customers" /> <ComboboxContent> {CUSTOMERS.map((customer) => ( <ComboboxItem key={customer.id} value={customer.id}> {customer.name} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Installation
The packages are a 0.x beta on npm, and their public API changes between beta releases without deprecation. One line installs the binding and the default theme.
pnpm add @slotted/react @slotted/theme @slotted/themesimport { Combobox, ComboboxContent, ComboboxGroup, ComboboxInput, ComboboxItem, ComboboxSeparator } from '@slotted/react';Descriptions
A description is the line under the label, for the detail that tells two similar options apart. The filter compares the label only, so typing a word from the description finds nothing.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const WAREHOUSES = [ { code: 'RNO', city: 'Reno, NV', detail: 'West · same-day cutoff 2:00 pm PT' }, { code: 'CMH', city: 'Columbus, OH', detail: 'Midwest · same-day cutoff 3:00 pm ET' }, { code: 'SAV', city: 'Savannah, GA', detail: 'Southeast · port of entry for ocean freight' }, { code: 'DFW', city: 'Dallas, TX', detail: 'South · opens November 2026' },];export default function ComboboxDescriptions() { return ( <Field> <FieldLabel>Ship from</FieldLabel> <Combobox> <ComboboxInput placeholder="Search warehouses" /> <ComboboxContent> {WAREHOUSES.map((warehouse) => ( <ComboboxItem key={warehouse.code} value={warehouse.code} description={warehouse.detail} > {warehouse.city} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Icons
The first column holds an icon in front of the label. In React icon takes any element; in Angular icon names a glyph, and an element of your own goes in through slComboboxItemIcon.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';import { Glyph, type GlyphName, Icon } from '@slotted/react/icon';const DOCUMENTS: { id: string; name: string; glyph: GlyphName }[] = [ { id: 'price-list', name: 'Q4 wholesale price list.xlsx', glyph: 'file-spreadsheet' }, { id: 'carrier-contract', name: 'Carrier contract 2026.pdf', glyph: 'file-text' }, { id: 'floor-plan', name: 'Reno floor plan.png', glyph: 'file-image' }, { id: 'returns-deck', name: 'Returns policy review.key', glyph: 'presentation' }, { id: 'product-photos', name: 'Autumn product photos.zip', glyph: 'file-archive' },];export default function ComboboxIcons() { return ( <Field> <FieldLabel>Attach a document</FieldLabel> <Combobox> <ComboboxInput placeholder="Search shared files" /> <ComboboxContent> {DOCUMENTS.map((document) => ( <ComboboxItem key={document.id} value={document.id} icon={ <Icon> <Glyph name={document.glyph} /> </Icon> } > {document.name} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Disabled options
A disabled option stays in the list, is announced as unavailable, and is skipped by every movement key. Put the reason in its description so the reader knows why it cannot be chosen.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const SERVICES = [ { id: 'usps-priority', name: 'USPS Priority Mail', note: '1–3 business days', disabled: false }, { id: 'ups-ground', name: 'UPS Ground', note: '1–5 business days', disabled: false }, { id: 'fedex-2day', name: 'FedEx 2Day', note: '2 business days', disabled: false }, { id: 'dhl-express', name: 'DHL Express Worldwide', note: 'International shipments only', disabled: true, }, { id: 'ups-next-day', name: 'UPS Next Day Air', note: 'Cutoff passed for today', disabled: true },];export default function ComboboxDisabledOptions() { return ( <Field> <FieldLabel>Shipping service</FieldLabel> <Combobox> <ComboboxInput placeholder="Search services" /> <ComboboxContent> {SERVICES.map((service) => ( <ComboboxItem key={service.id} value={service.id} description={service.note} disabled={service.disabled} > {service.name} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Groups
Groups give each run of options a name that assistive technology reads with them. A group whose options were all filtered away disappears with its heading.
import { Combobox, ComboboxContent, ComboboxGroup, ComboboxInput, ComboboxItem,} from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const CATALOG = [ { category: 'Kitchen', products: [ { sku: 'KIT-1042', name: 'Cast-iron skillet' }, { sku: 'KIT-1043', name: 'Stoneware mug' }, { sku: 'KIT-1051', name: 'Pour-over kettle' }, ], }, { category: 'Bags', products: [ { sku: 'BAG-2010', name: 'Canvas tote' }, { sku: 'BAG-2014', name: 'Trail daypack' }, { sku: 'BAG-2019', name: 'Weekender bag' }, ], }, { category: 'Stationery', products: [ { sku: 'STA-3002', name: 'Field notebook' }, { sku: 'STA-3007', name: 'Fountain pen' }, { sku: 'STA-3011', name: 'Brass stapler' }, ], },];export default function ComboboxGroups() { return ( <Field> <FieldLabel>Product</FieldLabel> <Combobox> <ComboboxInput placeholder="Search the catalog" /> <ComboboxContent> {CATALOG.map((group) => ( <ComboboxGroup key={group.category} label={group.category}> {group.products.map((product) => ( <ComboboxItem key={product.sku} value={product.sku}> {product.name} </ComboboxItem> ))} </ComboboxGroup> ))} </ComboboxContent> </Combobox> </Field> );}Filtering
The default filter is a locale-sensitive “contains” that ignores accents and case, so sao finds São Paulo. The mark covers the span the same comparison matched. locale sets the language of the comparison when it differs from the page.
Accents and case are ignored when matching.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const CITIES = [ 'São Paulo', 'Zürich', 'Montréal', 'Kraków', 'Malmö', 'Querétaro', 'Reykjavík', 'Düsseldorf',];export default function ComboboxFiltering() { return ( <Field> <FieldLabel>Destination city</FieldLabel> <Combobox> <ComboboxInput placeholder="Try “sao” or “zurich”" /> <ComboboxContent> {CITIES.map((city) => ( <ComboboxItem key={city} value={city}> {city} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription>Accents and case are ignored when matching.</FieldDescription> </Field> );}Custom filter
filter replaces the comparison with a function of the label and the query. Here SKUs match from their first character only. filter={null} turns filtering off for a list a server has already filtered.
Codes match from the first character, so “10” finds nothing.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const PRODUCTS = [ { sku: 'KIT-1042', name: 'Cast-iron skillet' }, { sku: 'KIT-1043', name: 'Stoneware mug' }, { sku: 'BAG-2010', name: 'Canvas tote' }, { sku: 'BAG-2014', name: 'Trail daypack' }, { sku: 'HOM-4010', name: 'Wool throw' }, { sku: 'HOM-4014', name: 'Brass desk lamp' }, { sku: 'STA-3010', name: 'Field notebook' },];const startsWith = (label: string, query: string) => label.toLowerCase().startsWith(query.toLowerCase());export default function ComboboxCustomFilter() { return ( <Field> <FieldLabel>SKU</FieldLabel> <Combobox filter={startsWith}> <ComboboxInput placeholder="KIT-, BAG-, HOM-…" /> <ComboboxContent> {PRODUCTS.map((product) => ( <ComboboxItem key={product.sku} value={product.sku} description={product.name}> {product.sku} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription> Codes match from the first character, so “10” finds nothing. </FieldDescription> </Field> );}Inline completion
autocomplete="both" writes the rest of the first match into the input as a selected range. The next character replaces it, Backspace removes it, and Tab or ArrowRight accepts it.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const TIME_ZONES = [ 'America/New_York', 'America/Chicago', 'America/Denver', 'America/Los_Angeles', 'Europe/London', 'Europe/Berlin', 'Asia/Tokyo', 'Australia/Sydney',];export default function ComboboxInlineCompletion() { return ( <Field> <FieldLabel>Time zone</FieldLabel> <Combobox autocomplete="both"> <ComboboxInput placeholder="Type “eu” or “am”" /> <ComboboxContent> {TIME_ZONES.map((zone) => ( <ComboboxItem key={zone} value={zone}> {zone} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Opening
openOn decides when the popup opens without the trigger button. input, the default, opens on typing or a press on the input; focus also opens when Tab reaches the input; manual opens only from the trigger and the arrow keys.
Typing or a press on the field opens it.
Every focus opens it, Tab included.
Only the button and the arrow keys open it.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem, type ComboboxOpenOn,} from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';const MODES: { openOn: ComboboxOpenOn; label: string; hint: string }[] = [ { openOn: 'input', label: 'Opens on typing', hint: 'Typing or a press on the field opens it.' }, { openOn: 'focus', label: 'Opens on focus', hint: 'Every focus opens it, Tab included.' }, { openOn: 'manual', label: 'Opens on request', hint: 'Only the button and the arrow keys open it.', },];const CHANNELS = ['Online store', 'Wholesale portal', 'Marketplace', 'Retail partners'];export default function ComboboxOpening() { return ( <Stack gap={5}> {MODES.map((mode) => ( <Field key={mode.openOn}> <FieldLabel>{mode.label}</FieldLabel> <Combobox openOn={mode.openOn}> <ComboboxInput placeholder="Sales channel" /> <ComboboxContent> {CHANNELS.map((channel) => ( <ComboboxItem key={channel} value={channel}> {channel} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription>{mode.hint}</FieldDescription> </Field> ))} </Stack> );}Highlighting the first match
With autoHighlight the first match is highlighted when the popup opens and after every character typed, so Enter takes it without an arrow key. loop makes ArrowDown wrap from the last option to the first. Both suit data entry where the reader types a few characters and moves on.
The first match is highlighted, so Enter takes it.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const UNITS = ['Each', 'Case of 6', 'Case of 12', 'Pallet', 'Kilogram', 'Pound', 'Meter', 'Liter'];export default function ComboboxAutoHighlight() { return ( <Field> <FieldLabel>Unit of measure</FieldLabel> <Combobox autoHighlight loop> <ComboboxInput placeholder="Type “ca” and press Enter" /> <ComboboxContent> {UNITS.map((unit) => ( <ComboboxItem key={unit} value={unit}> {unit} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription>The first match is highlighted, so Enter takes it.</FieldDescription> </Field> );}Sizes
Three steps, sm, md and lg, that match the height of the text field and select of the same size. An unset size follows the field around the combobox.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem, type ComboboxSize,} from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';const SIZES: { size: ComboboxSize; label: string }[] = [ { size: 'sm', label: 'Small' }, { size: 'md', label: 'Medium' }, { size: 'lg', label: 'Large' },];const WAREHOUSES = ['Reno, NV', 'Columbus, OH', 'Savannah, GA'];export default function ComboboxSizes() { return ( <Stack gap={5}> {SIZES.map((step) => ( <Field key={step.size}> <FieldLabel>{step.label}</FieldLabel> <Combobox size={step.size} defaultInputValue="Reno, NV" defaultValue="Reno, NV"> <ComboboxInput /> <ComboboxContent> {WAREHOUSES.map((warehouse) => ( <ComboboxItem key={warehouse} value={warehouse}> {warehouse} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> ))} </Stack> );}Variants
outline is the default frame. subtle fills the control for a form set on a tinted surface. plain draws no frame at rest, for a table cell or a toolbar, and still shows hover and focus.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem, type ComboboxVariant,} from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';const VARIANTS: { variant: ComboboxVariant; label: string }[] = [ { variant: 'outline', label: 'Outline' }, { variant: 'subtle', label: 'Subtle' }, { variant: 'plain', label: 'Plain' },];const WAREHOUSES = ['Reno, NV', 'Columbus, OH', 'Savannah, GA'];export default function ComboboxVariants() { return ( <Stack gap={5}> {VARIANTS.map((step) => ( <Field key={step.variant}> <FieldLabel>{step.label}</FieldLabel> <Combobox variant={step.variant}> <ComboboxInput placeholder="Search warehouses" /> <ComboboxContent> {WAREHOUSES.map((warehouse) => ( <ComboboxItem key={warehouse} value={warehouse}> {warehouse} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> ))} </Stack> );}Width
fullWidth={false} lets the control keep its own width instead of filling the field. The popup is never narrower than the control and grows to its longest option, up to a maximum measure; width="anchor" pins it to the control’s width.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const ZONES = [ { id: 'pacific', label: '(UTC−08:00) Pacific Time — Los Angeles, Vancouver' }, { id: 'mountain', label: '(UTC−07:00) Mountain Time — Denver, Calgary' }, { id: 'central', label: '(UTC−06:00) Central Time — Chicago, Mexico City' }, { id: 'eastern', label: '(UTC−05:00) Eastern Time — New York, Toronto' }, { id: 'london', label: '(UTC+00:00) Greenwich Mean Time — London, Lisbon' },];export default function ComboboxPopupWidth() { return ( <Field> <FieldLabel>Report time zone</FieldLabel> <Combobox fullWidth={false} width="content"> <ComboboxInput placeholder="Search zones" /> <ComboboxContent> {ZONES.map((zone) => ( <ComboboxItem key={zone.id} value={zone.id}> {zone.label} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Disabled and read-only
A disabled combobox takes no input and is skipped by Tab. A read-only combobox keeps the text selectable and copyable and never opens. Both follow the field around them.
Locked while the transfer is in transit.
Set by the contract. The text can still be selected and copied.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';export default function ComboboxStates() { return ( <Stack gap={5}> <Field disabled> <FieldLabel>Warehouse</FieldLabel> <Combobox defaultInputValue="Reno, NV" defaultValue="RNO"> <ComboboxInput /> <ComboboxContent> <ComboboxItem value="RNO">Reno, NV</ComboboxItem> <ComboboxItem value="CMH">Columbus, OH</ComboboxItem> </ComboboxContent> </Combobox> <FieldDescription>Locked while the transfer is in transit.</FieldDescription> </Field> <Field readOnly> <FieldLabel>Billing entity</FieldLabel> <Combobox defaultInputValue="Northwind Trading Co." defaultValue="northwind-us"> <ComboboxInput /> <ComboboxContent> <ComboboxItem value="northwind-us">Northwind Trading Co.</ComboboxItem> <ComboboxItem value="northwind-eu">Northwind Europe B.V.</ComboboxItem> </ComboboxContent> </Combobox> <FieldDescription> Set by the contract. The text can still be selected and copied. </FieldDescription> </Field> </Stack> );}Clearing
The clear button appears once the input holds text and resets both the text and the value in one press. Focus returns to the input. Set clearable={false} for a value that must always be present.
Optional. Clearing it routes orders by distance.
Every account has terms, so there is nothing to clear.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';export default function ComboboxClearable() { return ( <Stack gap={5}> <Field> <FieldLabel>Default warehouse</FieldLabel> <Combobox defaultInputValue="Columbus, OH" defaultValue="CMH"> <ComboboxInput /> <ComboboxContent> <ComboboxItem value="RNO">Reno, NV</ComboboxItem> <ComboboxItem value="CMH">Columbus, OH</ComboboxItem> <ComboboxItem value="SAV">Savannah, GA</ComboboxItem> </ComboboxContent> </Combobox> <FieldDescription>Optional. Clearing it routes orders by distance.</FieldDescription> </Field> <Field> <FieldLabel>Payment terms</FieldLabel> <Combobox clearable={false} defaultInputValue="Net 30" defaultValue="net-30"> <ComboboxInput /> <ComboboxContent> <ComboboxItem value="prepaid">Prepaid</ComboboxItem> <ComboboxItem value="net-30">Net 30</ComboboxItem> <ComboboxItem value="net-45">Net 45</ComboboxItem> </ComboboxContent> </Combobox> <FieldDescription>Every account has terms, so there is nothing to clear.</FieldDescription> </Field> </Stack> );}In a field
Inside a field the label names the input, and the description and the error are read with it. required and invalid on the field reach the input as the native required attribute and aria-invalid.
Receives the renewal reminders for this account.
Error:4900 is closed. Choose an open cost center.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldError, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';const OWNERS = ['Avery Collins', 'Kenji Watanabe', 'Lucía Fernández', 'Omar Haddad'];const COST_CENTERS = ['4100 Fulfilment', '4200 Customer care', '4300 Marketing'];export default function ComboboxField() { return ( <Stack gap={5}> <Field required> <FieldLabel>Account manager</FieldLabel> <Combobox> <ComboboxInput placeholder="Search people" /> <ComboboxContent> {OWNERS.map((owner) => ( <ComboboxItem key={owner} value={owner}> {owner} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription>Receives the renewal reminders for this account.</FieldDescription> </Field> <Field invalid required> <FieldLabel>Cost center</FieldLabel> <Combobox defaultInputValue="4900"> <ComboboxInput /> <ComboboxContent> {COST_CENTERS.map((center) => ( <ComboboxItem key={center} value={center}> {center} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldError>4900 is closed. Choose an open cost center.</FieldError> </Field> </Stack> );}In a form
The form receives the value, never the typed text. In React name renders a hidden input that FormData reads. In Angular the combobox is a form control: formControlName, formControl and ngModel bind the value, and Validators.required applies to it.
import { useState } from 'react';import type { SubmitEvent } from 'react';import { Button } from '@slotted/react/button';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldError, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const WAREHOUSES = [ { code: 'RNO', city: 'Reno, NV' }, { code: 'CMH', city: 'Columbus, OH' }, { code: 'SAV', city: 'Savannah, GA' },];export default function ComboboxForm() { const [missing, setMissing] = useState(false); const [submitted, setSubmitted] = useState<string | null>(null); const submit = (event: SubmitEvent<HTMLFormElement>) => { event.preventDefault(); const warehouse = new FormData(event.currentTarget).get('warehouse'); setMissing(!warehouse); setSubmitted(warehouse ? `warehouse=${String(warehouse)}` : null); }; return ( <form noValidate onSubmit={submit}> <Stack gap={4}> <Field required invalid={missing}> <FieldLabel>Fulfil from</FieldLabel> <Combobox name="warehouse" onValueChange={(next) => next && setMissing(false)}> <ComboboxInput placeholder="Search warehouses" /> <ComboboxContent> {WAREHOUSES.map((warehouse) => ( <ComboboxItem key={warehouse.code} value={warehouse.code}> {warehouse.city} </ComboboxItem> ))} </ComboboxContent> </Combobox> {missing && <FieldError>Choose the warehouse that ships this order.</FieldError>} </Field> <Inline gap={3} align="center"> <Button type="submit">Create transfer</Button> {submitted && ( <Text size="sm" tone="muted"> Submitted {submitted} </Text> )} </Inline> </Stack> </form> );}Controlled text and value
The text in the input and the chosen value are two separate states. Typing changes only the text; choosing an option changes both. A controlled combobox owns both, so code that sets the value sets the text as well, as the button here does.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';import { Inline } from '@slotted/react/inline';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const PEOPLE = [ { id: 'avery', name: 'Avery Collins' }, { id: 'kenji', name: 'Kenji Watanabe' }, { id: 'lucia', name: 'Lucía Fernández' }, { id: 'ruth', name: 'Ruth Adeyemi' }, { id: 'tomasz', name: 'Tomasz Nowak' },];export default function ComboboxControlled() { const [text, setText] = useState(''); const [value, setValue] = useState<string | null>(null); const assignToMe = () => { setValue('ruth'); setText('Ruth Adeyemi'); }; return ( <Stack gap={4}> <Field> <FieldLabel>Reviewer</FieldLabel> <Combobox inputValue={text} onInputValueChange={setText} value={value} onValueChange={setValue} > <ComboboxInput placeholder="Search people" /> <ComboboxContent> {PEOPLE.map((person) => ( <ComboboxItem key={person.id} value={person.id}> {person.name} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> <Inline gap={3} align="center"> <Button size="sm" variant="outline" onClick={assignToMe}> Assign to me </Button> <Text size="sm" tone="muted"> Text “{text}” · Value {value ?? 'none'} </Text> </Inline> </Stack> );}Custom values
With allowsCustomValue the typed text becomes the value when the reader presses Enter or leaves the input. Without it, text that matches no option goes back to the label of the last chosen option.
Value: none
import { useState } from 'react';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const BOXES = [ { id: 'small', label: 'Small · 20 × 15 × 10 cm' }, { id: 'medium', label: 'Medium · 35 × 25 × 15 cm' }, { id: 'large', label: 'Large · 50 × 40 × 30 cm' },];export default function ComboboxCustomValue() { const [value, setValue] = useState<string | null>(null); return ( <Field> <FieldLabel>Box size</FieldLabel> <Combobox allowsCustomValue value={value} onValueChange={setValue}> <ComboboxInput placeholder="Pick a box or type dimensions" /> <ComboboxContent> {BOXES.map((box) => ( <ComboboxItem key={box.id} value={box.id}> {box.label} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription>Value: {value ?? 'none'}</FieldDescription> </Field> );}Creating options
When nothing matches, the last option offers to create what was typed. It is an option like the others: ArrowDown reaches it and Enter takes it. Taking it reports the query and selects nothing, so your handler adds the option and selects it. The prop is onCreate in React; in Angular it is creatable with the (create) output.
6 categories
import { useState } from 'react';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const CATEGORIES = ['Apparel', 'Bags', 'Home', 'Kitchen', 'Stationery', 'Outdoor'];export default function ComboboxCreatable() { const [categories, setCategories] = useState(CATEGORIES); const [value, setValue] = useState<string | null>(null); const create = (query: string) => { setCategories((held) => [...held, query]); setValue(query); }; return ( <Field> <FieldLabel>Category</FieldLabel> <Combobox onCreate={create} value={value} onValueChange={setValue}> <ComboboxInput placeholder="Type “Garden” to add it" /> <ComboboxContent> {categories.map((category) => ( <ComboboxItem key={category} value={category}> {category} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription>{categories.length} categories</FieldDescription> </Field> );}Searching a server
For results that come from a server, turn the filter off, control the text, and set loading while a request is in flight. The trigger shows a spinner, the popup shows three placeholder rows, and the status row announces the wait. Debounce the request in your own code; the combobox reports every keystroke.
import { useEffect, useState } from 'react';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';interface Customer { id: string; name: string; city: string;}const DIRECTORY: Customer[] = [ { id: 'brightline', name: 'Brightline Studio', city: 'Portland, OR' }, { id: 'harbor-pine', name: 'Harbor & Pine', city: 'Seattle, WA' }, { id: 'northgate', name: 'Northgate Labs', city: 'Austin, TX' }, { id: 'quill', name: 'Quill & Co.', city: 'Brooklyn, NY' }, { id: 'solstice', name: 'Solstice Outdoor', city: 'Boulder, CO' }, { id: 'verde', name: 'Verde Kitchen', city: 'Oakland, CA' }, { id: 'atlas', name: 'Atlas Freight', city: 'Memphis, TN' }, { id: 'juniper', name: 'Juniper Health', city: 'Minneapolis, MN' }, { id: 'kestrel', name: 'Kestrel Robotics', city: 'Pittsburgh, PA' }, { id: 'larkspur', name: 'Larkspur Books', city: 'Asheville, NC' }, { id: 'meridian', name: 'Meridian Hotels', city: 'Chicago, IL' }, { id: 'oakline', name: 'Oakline Furniture', city: 'Grand Rapids, MI' }, { id: 'pelican', name: 'Pelican Coffee', city: 'Tampa, FL' }, { id: 'saltmarsh', name: 'Saltmarsh Dairy', city: 'Burlington, VT' }, { id: 'tidewater', name: 'Tidewater Supply', city: 'Norfolk, VA' },];/** Stands in for a request to the server, which answers after 600 ms. */function searchCustomers(query: string): Promise<Customer[]> { const needle = query.trim().toLowerCase(); const found = DIRECTORY.filter((customer) => customer.name.toLowerCase().includes(needle)); return new Promise((resolve) => setTimeout(() => resolve(found), 600));}export default function ComboboxAsyncSearch() { const [query, setQuery] = useState(''); const [results, setResults] = useState<Customer[]>([]); const [loading, setLoading] = useState(false); useEffect(() => { if (query.trim() === '') { setResults([]); setLoading(false); return; } let current = true; setLoading(true); const debounce = setTimeout(() => { void searchCustomers(query).then((found) => { if (!current) return; setResults(found); setLoading(false); }); }, 250); return () => { current = false; clearTimeout(debounce); }; }, [query]); return ( <Field> <FieldLabel>Customer</FieldLabel> <Combobox filter={null} inputValue={query} onInputValueChange={setQuery} loading={loading} messages={{ empty: query.trim() === '' ? 'Type a name to search.' : 'No customer by that name.', }} > <ComboboxInput placeholder="Search 15 customers" /> <ComboboxContent> {results.map((customer) => ( <ComboboxItem key={customer.id} value={customer.id} description={customer.city}> {customer.name} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Search errors
A failed request is your state to show. Here the field turns invalid, the error says what happened, the typed text stays, and a retry button repeats the last search. The popup’s empty message changes to match. The simulated service fails its first request only.
import { useRef, useState } from 'react';import { Button } from '@slotted/react/button';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldError, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';const CARRIERS = ['UPS', 'FedEx', 'DHL', 'USPS', 'OnTrac', 'LaserShip'];/** Stands in for a rate service that fails its first request and answers after. */let outage = true;function searchCarriers(query: string): Promise<string[]> { const needle = query.trim().toLowerCase(); return new Promise((resolve, reject) => setTimeout(() => { if (outage) { outage = false; reject(new Error('The rate service did not answer.')); return; } resolve(CARRIERS.filter((carrier) => carrier.toLowerCase().includes(needle))); }, 500), );}export default function ComboboxSearchError() { const [query, setQuery] = useState(''); const [results, setResults] = useState<string[]>([]); const [loading, setLoading] = useState(false); const [failed, setFailed] = useState(false); const latest = useRef(0); const search = (text: string) => { const request = ++latest.current; setLoading(true); setFailed(false); searchCarriers(text).then( (found) => { if (request !== latest.current) return; setResults(found); setLoading(false); }, () => { if (request !== latest.current) return; setResults([]); setFailed(true); setLoading(false); }, ); }; const type = (text: string) => { setQuery(text); if (text.trim() !== '') search(text); }; return ( <Stack gap={3}> <Field invalid={failed}> <FieldLabel>Carrier</FieldLabel> <Combobox filter={null} inputValue={query} onInputValueChange={type} loading={loading} messages={{ empty: failed ? 'Rates are unavailable.' : 'No carrier by that name.' }} > <ComboboxInput placeholder="Search carriers" /> <ComboboxContent> {results.map((carrier) => ( <ComboboxItem key={carrier} value={carrier}> {carrier} </ComboboxItem> ))} </ComboboxContent> </Combobox> {failed && <FieldError>The rate service did not answer. Your text is kept.</FieldError>} </Field> {failed && ( <div> <Button size="sm" variant="outline" onClick={() => search(query)}> Retry </Button> </div> )} </Stack> );}Loading more results
onLoadMore (loadMore in Angular) fires when the end of the list scrolls into view, and you append the next page. total and position give each option its place in the full result set through aria-setsize and aria-posinset.
Thirty at a time; scrolling to the end fetches the next page.
import { useMemo, useRef, useState } from 'react';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const PRODUCTS = [ 'Canvas tote', 'Merino beanie', 'Stoneware mug', 'Linen apron', 'Trail daypack', 'Wool throw', 'Ceramic planter', 'Field notebook', 'Rain shell', 'Leather wallet', 'Weekender bag', 'Cotton crewneck', 'Camp mug', 'Insulated bottle', 'Chambray shirt', 'Waffle towel', 'Beeswax candle', 'Rattan basket', 'Hiking socks', 'Down vest', 'Sketchbook', 'Wool blanket', 'Market crossbody', 'Felt slippers',];const COLORS = [ 'Natural', 'Charcoal', 'Olive', 'Rust', 'Navy', 'Sand', 'Forest', 'Slate', 'Clay', 'Ink',];const SKUS = PRODUCTS.flatMap((product, row) => COLORS.map((color, column) => ({ sku: `NW-${1001 + row * COLORS.length + column}`, label: `${product}, ${color}`, })),);const PAGE = 30;export default function ComboboxLoadMore() { const [query, setQuery] = useState(''); const [shown, setShown] = useState(PAGE); const [loading, setLoading] = useState(false); const request = useRef(0); /* The server's answer: every SKU whose label holds the query, a page at a time. */ const matching = useMemo(() => { const needle = query.trim().toLowerCase(); return SKUS.filter((item) => item.label.toLowerCase().includes(needle)); }, [query]); const type = (text: string) => { request.current += 1; setQuery(text); setShown(PAGE); setLoading(false); }; const loadMore = () => { if (loading || shown >= matching.length) return; const current = ++request.current; setLoading(true); setTimeout(() => { if (current !== request.current) return; setShown((count) => count + PAGE); setLoading(false); }, 500); }; return ( <Field> <FieldLabel>Variant</FieldLabel> <Combobox filter={null} inputValue={query} onInputValueChange={type} loading={loading} onLoadMore={loadMore} total={matching.length} > <ComboboxInput placeholder="Search 240 SKUs" /> <ComboboxContent> {matching.slice(0, shown).map((item, index) => ( <ComboboxItem key={item.sku} value={item.sku} description={item.sku} position={index + 1} > {item.label} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription> Thirty at a time; scrolling to the end fetches the next page. </FieldDescription> </Field> );}Long lists
The combobox renders every option it is given and does not virtualize. PageDown and PageUp move the highlight ten options at a time. For collections larger than a few hundred options, load pages as shown above.
Page Down and Page Up move ten bins at a time.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const BINS = Array.from({ length: 240 }, (_, index) => { const aisle = String(Math.floor(index / 20) + 1).padStart(2, '0'); const bay = String((index % 20) + 1).padStart(2, '0'); return { id: `A${aisle}-B${bay}`, detail: `Aisle ${Number(aisle)}, bay ${Number(bay)} · Reno` };});export default function ComboboxLongList() { return ( <Field> <FieldLabel>Put-away bin</FieldLabel> <Combobox> <ComboboxInput placeholder="Search 240 bins" /> <ComboboxContent> {BINS.map((bin) => ( <ComboboxItem key={bin.id} value={bin.id} description={bin.detail}> {bin.id} </ComboboxItem> ))} </ComboboxContent> </Combobox> <FieldDescription>Page Down and Page Up move ten bins at a time.</FieldDescription> </Field> );}Long labels
A label wraps to two lines and then truncates, with the whole text still in the DOM for the filter and for assistive technology. An unbroken identifier breaks inside the column instead of widening the popup.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const ACCOUNTS = [ { id: '4010', label: '4010 · Revenue, wholesale channel, net of returns, allowances and early-payment discounts', }, { id: '4020', label: '4020 · Revenue, online store' }, { id: 'urn', label: 'urn:northwind:ledger:4030-9f2c41ab8de07c5511903fbe', description: 'Imported from the previous ledger', }, { id: '5100', label: '5100 · Cost of goods sold, including inbound freight and duties', description: 'Posted when an order ships, at the weighted average cost of the warehouse', },];export default function ComboboxLongLabels() { return ( <Field> <FieldLabel>Ledger account</FieldLabel> <Combobox> <ComboboxInput placeholder="Search accounts" /> <ComboboxContent> {ACCOUNTS.map((account) => ( <ComboboxItem key={account.id} value={account.id} description={account.description}> {account.label} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Messages
messages replaces any of the six phrases the combobox writes: clear, trigger, create, empty, loading and count. count and create take ICU placeholders. Phrases you leave out come from the active locale.
import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const CARRIERS = ['UPS', 'FedEx', 'DHL', 'USPS', 'OnTrac'];export default function ComboboxCustomMessages() { return ( <Field> <FieldLabel>Carrier</FieldLabel> <Combobox messages={{ clear: 'Clear carrier', count: '{count, plural, one {# carrier} other {# carriers}}', empty: 'No carrier by that name. Check the spelling on the label.', }} > <ComboboxInput placeholder="Type “royal mail”" /> <ComboboxContent> {CARRIERS.map((carrier) => ( <ComboboxItem key={carrier} value={carrier}> {carrier} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Application defaults
Set an axis once for a whole subtree: ComboboxDefaultsProvider in React, provideComboboxDefaults() in Angular. A prop on a single combobox still wins.
import { Combobox, ComboboxContent, ComboboxDefaultsProvider, ComboboxInput, ComboboxItem,} from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';import { Stack } from '@slotted/react/stack';const WAREHOUSES = ['Reno, NV', 'Columbus, OH', 'Savannah, GA'];const CARRIERS = ['UPS', 'FedEx', 'DHL', 'USPS'];export default function ComboboxAppDefaults() { return ( <ComboboxDefaultsProvider variant="subtle" autoHighlight> <Stack gap={4}> <Field> <FieldLabel>Warehouse</FieldLabel> <Combobox> <ComboboxInput placeholder="Any warehouse" /> <ComboboxContent> {WAREHOUSES.map((warehouse) => ( <ComboboxItem key={warehouse} value={warehouse}> {warehouse} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> <Field> <FieldLabel>Carrier</FieldLabel> <Combobox> <ComboboxInput placeholder="Any carrier" /> <ComboboxContent> {CARRIERS.map((carrier) => ( <ComboboxItem key={carrier} value={carrier}> {carrier} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> </Stack> </ComboboxDefaultsProvider> );}Assignee picker
A person picker with an avatar in the icon column, the role in the description, and an unavailable person kept in the list but disabled. autoHighlight lets the reader type a few letters of a name and press Enter.
import { Avatar } from '@slotted/react/avatar';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Field, FieldLabel } from '@slotted/react/field';const PEOPLE = [ { id: 'avery', name: 'Avery Collins', role: 'Fulfilment lead', away: false }, { id: 'kenji', name: 'Kenji Watanabe', role: 'Customer care', away: false }, { id: 'lucia', name: 'Lucía Fernández', role: 'Account manager', away: false }, { id: 'ruth', name: 'Ruth Adeyemi', role: 'On leave until 14 October', away: true }, { id: 'tomasz', name: 'Tomasz Nowak', role: 'Warehouse supervisor, Reno', away: false }, { id: 'omar', name: 'Omar Haddad', role: 'Finance', away: false },];export default function ComboboxAssigneePicker() { return ( <Field> <FieldLabel>Assignee</FieldLabel> <Combobox autoHighlight> <ComboboxInput placeholder="Assign to…" /> <ComboboxContent> {PEOPLE.map((person) => ( <ComboboxItem key={person.id} value={person.id} description={person.role} disabled={person.away} icon={<Avatar name={person.name} size="xs" decorative />} > {person.name} </ComboboxItem> ))} </ComboboxContent> </Combobox> </Field> );}Country or region picker
Countries grouped by region, with the currency and dialing code as the description. The locale-sensitive filter finds Côte d’Ivoire from cote and Türkiye from turkiye, and name submits the country code.
Sets the currency and the phone prefix on the invoice.
import { Combobox, ComboboxContent, ComboboxGroup, ComboboxInput, ComboboxItem,} from '@slotted/react/combobox';import { Field, FieldDescription, FieldLabel } from '@slotted/react/field';const REGIONS = [ { region: 'Americas', countries: [ { code: 'BR', name: 'Brazil', detail: 'BRL · +55' }, { code: 'CA', name: 'Canada', detail: 'CAD · +1' }, { code: 'MX', name: 'Mexico', detail: 'MXN · +52' }, { code: 'US', name: 'United States', detail: 'USD · +1' }, ], }, { region: 'Europe', countries: [ { code: 'FR', name: 'France', detail: 'EUR · +33' }, { code: 'DE', name: 'Germany', detail: 'EUR · +49' }, { code: 'PL', name: 'Poland', detail: 'PLN · +48' }, { code: 'CH', name: 'Switzerland', detail: 'CHF · +41' }, { code: 'TR', name: 'Türkiye', detail: 'TRY · +90' }, { code: 'GB', name: 'United Kingdom', detail: 'GBP · +44' }, ], }, { region: 'Asia Pacific', countries: [ { code: 'AU', name: 'Australia', detail: 'AUD · +61' }, { code: 'JP', name: 'Japan', detail: 'JPY · +81' }, { code: 'SG', name: 'Singapore', detail: 'SGD · +65' }, { code: 'VN', name: 'Việt Nam', detail: 'VND · +84' }, ], }, { region: 'Middle East and Africa', countries: [ { code: 'CI', name: 'Côte d’Ivoire', detail: 'XOF · +225' }, { code: 'EG', name: 'Egypt', detail: 'EGP · +20' }, { code: 'KE', name: 'Kenya', detail: 'KES · +254' }, { code: 'AE', name: 'United Arab Emirates', detail: 'AED · +971' }, ], },];export default function ComboboxCountryPicker() { return ( <Field required> <FieldLabel>Country or region</FieldLabel> <Combobox autoHighlight name="country"> <ComboboxInput placeholder="Search countries" /> <ComboboxContent> {REGIONS.map((group) => ( <ComboboxGroup key={group.region} label={group.region}> {group.countries.map((country) => ( <ComboboxItem key={country.code} value={country.code} description={country.detail}> {country.name} </ComboboxItem> ))} </ComboboxGroup> ))} </ComboboxContent> </Combobox> <FieldDescription>Sets the currency and the phone prefix on the invoice.</FieldDescription> </Field> );}Filter facets
A row of compact comboboxes above a list, one per facet. Each control keeps its own width, the popups size to their options, and one button clears every facet by resetting both the value and the text.
import { useState } from 'react';import { Button } from '@slotted/react/button';import { Combobox, ComboboxContent, ComboboxInput, ComboboxItem } from '@slotted/react/combobox';import { Inline } from '@slotted/react/inline';import { Text } from '@slotted/react/typography';type Facet = 'warehouse' | 'carrier' | 'owner';const WAREHOUSES = ['Reno, NV', 'Columbus, OH', 'Savannah, GA'];const CARRIERS = ['UPS', 'FedEx', 'DHL', 'USPS'];const OWNERS = ['Avery Collins', 'Kenji Watanabe', 'Lucía Fernández', 'Omar Haddad'];const FACETS: { id: Facet; label: string; options: string[] }[] = [ { id: 'warehouse', label: 'Warehouse', options: WAREHOUSES }, { id: 'carrier', label: 'Carrier', options: CARRIERS }, { id: 'owner', label: 'Owner', options: OWNERS },];/** Open orders, counted per warehouse, carrier and owner. */const ORDERS = WAREHOUSES.flatMap((warehouse, w) => CARRIERS.flatMap((carrier, c) => OWNERS.map((owner, o) => ({ warehouse, carrier, owner, count: 1 + ((w + 2 * c + 3 * o) % 5) })), ),);const TOTAL = ORDERS.reduce((sum, row) => sum + row.count, 0);const NONE: Record<Facet, string | null> = { warehouse: null, carrier: null, owner: null };const EMPTY: Record<Facet, string> = { warehouse: '', carrier: '', owner: '' };export default function ComboboxFilterFacets() { const [chosen, setChosen] = useState(NONE); const [texts, setTexts] = useState(EMPTY); const matching = ORDERS.filter((row) => FACETS.every((facet) => chosen[facet.id] === null || row[facet.id] === chosen[facet.id]), ).reduce((sum, row) => sum + row.count, 0); const active = FACETS.filter((facet) => chosen[facet.id] !== null).length; const clear = () => { setChosen(NONE); setTexts(EMPTY); }; return ( <Inline gap={2} align="center" wrap="wrap"> {FACETS.map((facet) => ( <Combobox key={facet.id} size="sm" fullWidth={false} width="content" value={chosen[facet.id]} onValueChange={(next) => setChosen((held) => ({ ...held, [facet.id]: next }))} inputValue={texts[facet.id]} onInputValueChange={(next) => setTexts((held) => ({ ...held, [facet.id]: next }))} > <ComboboxInput aria-label={facet.label} placeholder={facet.label} /> <ComboboxContent aria-label={facet.label}> {facet.options.map((option) => ( <ComboboxItem key={option} value={option}> {option} </ComboboxItem> ))} </ComboboxContent> </Combobox> ))} <Button size="sm" variant="ghost" disabled={active === 0} onClick={clear}> Clear filters </Button> <Text size="sm" tone="muted"> {matching} of {TOTAL} orders </Text> </Inline> );}Global search
A search input alone in a header opens on focus, so the reader sees results before typing. Groups separate customers from orders, and the icon tells the two apart at a glance.
import { useState } from 'react';import { Combobox, ComboboxContent, ComboboxGroup, ComboboxInput, ComboboxItem,} from '@slotted/react/combobox';import { Glyph, Icon } from '@slotted/react/icon';import { Stack } from '@slotted/react/stack';import { Text } from '@slotted/react/typography';const CUSTOMERS = [ { id: 'brightline', name: 'Brightline Studio', city: 'Portland, OR' }, { id: 'harbor-pine', name: 'Harbor & Pine', city: 'Seattle, WA' }, { id: 'northgate', name: 'Northgate Labs', city: 'Austin, TX' },];const ORDERS = [ { id: '10482', customer: 'Brightline Studio', total: '$1,284.00' }, { id: '10479', customer: 'Atlas Freight', total: '$356.40' }, { id: '10471', customer: 'Northgate Labs', total: '$2,910.15' },];const LABELS = new Map<string, string>([ ...CUSTOMERS.map((customer) => [`customer:${customer.id}`, customer.name] as const), ...ORDERS.map((order) => [`order:${order.id}`, `Order ${order.id}`] as const),]);export default function ComboboxGlobalSearch() { const [opened, setOpened] = useState<string | null>(null); return ( <Stack gap={3}> <Combobox openOn="focus" size="sm" onValueChange={setOpened}> <ComboboxInput aria-label="Search Northwind" placeholder="Search customers and orders" /> <ComboboxContent aria-label="Search Northwind"> <ComboboxGroup label="Customers"> {CUSTOMERS.map((customer) => ( <ComboboxItem key={customer.id} value={`customer:${customer.id}`} description={customer.city} icon={ <Icon> <Glyph name="person" /> </Icon> } > {customer.name} </ComboboxItem> ))} </ComboboxGroup> <ComboboxGroup label="Orders"> {ORDERS.map((order) => ( <ComboboxItem key={order.id} value={`order:${order.id}`} description={`${order.customer} · ${order.total}`} icon={ <Icon> <Glyph name="file-text" /> </Icon> } > {`Order ${order.id}`} </ComboboxItem> ))} </ComboboxGroup> </ComboboxContent> </Combobox> <Text size="sm" tone="muted"> {opened === null ? 'Focus the field to see every result.' : `Opening ${LABELS.get(opened)}`} </Text> </Stack> );}Accessibility
| Key | Effect | Focus |
|---|---|---|
| ArrowDown | closed, opens and highlights the first option; open, moves the highlight to the next option, wrapping only when loop is true | stays on the input, and the caret does not move |
| ArrowUp | closed, opens and highlights the last option, which is the pattern's optional Up Arrow; open, moves the highlight to the previous option | the input, caret unmoved |
| Alt+ArrowDown | opens the popup without moving the highlight | the input |
| Alt+ArrowUp | closes the popup | the input |
| Enter | commits the highlighted option, closes, and puts the caret at the end of the accepted value; with no highlight and allowsCustomValue, commits the typed text; with no highlight and no custom value, closes and reverts the text | the input |
| Escape | open, closes and keeps the typed text; closed, reverts the text to the committed option's label, and clears the selection when the text was already that label. Both steps are optional in the pattern and both are named in it. | the input |
| Home | the browser's caret movement, never intercepted, which is the pattern's editable branch | the input, caret at the first character |
| End | the browser's caret movement, never intercepted | the input, caret after the last character |
| PageDown | moves the highlight ten options on, or to the last, and never wraps. Optional in the pattern for a grid popup and absent for a listbox one; adopted because a filtered list of two hundred is the case this family exists for. | the input |
| PageUp | moves the highlight ten options back, or to the first, and never wraps | the input |
| ArrowLeft | the browser's caret movement, never intercepted | the input |
| ArrowRight | the browser's caret movement, never intercepted. With autocomplete="both" and a completion string showing, it accepts the completion by collapsing the selection to its end, which is what the caret key already does. | the input |
| Backspace | the browser's text editing, never intercepted. It also withdraws the completion string, because a reader deleting a character is not asking for one back. | the input |
| Delete | the browser's text editing, never intercepted, and it withdraws the completion string for the same reason | the input |
| Printable character | typed into the input, which filters the collection. Never intercepted — the pattern's IMPORTANT note asks that script not capture the keys the browser uses for text editing. | the input |
| Tab | closes without committing a highlight, and accepts a showing completion string. A highlight the reader arrowed past is not a choice they made, which is where this family differs from select. | the next element in the page |
- The input has role="combobox" with aria-autocomplete, aria-expanded and aria-controls. The popup has role="listbox", and each row has role="option". The trigger button is out of the tab sequence, as the ARIA combobox pattern requires.
- Focus stays on the input, so Home, End, ArrowLeft, ArrowRight, Backspace and Delete keep their text-editing behavior. The highlight moves through aria-activedescendant, and the caret does not move with it.
- Escape works in two steps, both named by the pattern. With the popup open, it closes the popup and keeps the text. With the popup closed, it restores the label of the chosen option, and a second press clears the selection.
- The status row is a polite live region. It announces how many options matched, and "Loading…" while a request is in flight.
- Tab commits nothing: an option the reader arrowed past is not a choice, which is where the combobox differs from the select. Tab does accept an inline completion that is still showing.
API
Combobox
Props
inputValuestring- The text in the input. Passing it makes the text controlled.
defaultInputValuestring- The initial text of an uncontrolled input, read once.
valuestring | null- The key of the chosen option, which is separate from the typed text. Passing it makes the value controlled.
defaultValuestring | null- The initial value of an uncontrolled combobox. It sets the key, not the text.
openboolean- Whether the popup is open. Passing it makes the open state controlled.
defaultOpenbooleanDefaultfalse- Whether an uncontrolled popup starts open.
highlightedValuestring | null- The key of the highlighted option, which is separate from the chosen one.
defaultHighlightedValuestring | null- The initial highlight of an uncontrolled combobox.
filter((label, query) => boolean) | null- The comparison between a label and the query. Unset uses a locale-sensitive contains; null turns filtering off for a list a server has already filtered.
localestring- The BCP 47 language of the default filter. The active locale when unset.
itemsComboboxItems- Labels for values, so a closed combobox can show the label of an option it has not rendered.
namestring- The name the value is submitted under. Renders a hidden input that carries the chosen key.
formstring- The id of the form the value is submitted with, when it is not the enclosing one.
totalnumber- The size of the whole collection, written to aria-setsize on each option.
autocomplete'none' | 'list' | 'both'Defaultlist- What typing does: none keeps every option, list filters the options, and both also completes the first match inline. Written to aria-autocomplete.
openOn'input' | 'focus' | 'manual'Defaultinput- When the popup opens without the trigger: on typing or a press on the input (input), on every focus and press (focus), or only from the trigger and the arrow keys (manual).
allowsCustomValuebooleanDefaultfalse- Whether text that matches no option becomes the value on Enter or blur.
autoHighlightbooleanDefaultfalse- Whether the first match is highlighted when the popup opens and after each query typed, so Enter takes it. A chosen option that is showing takes precedence.
highlightMatchbooleanDefaulttrue- Whether the part of each label the query matched is marked.
size'sm' | 'md' | 'lg'Defaultmd- The control size. Unset follows the enclosing field.
variant'outline' | 'subtle' | 'plain'Defaultoutline- How much frame the control draws.
side'bottom' | 'top' | 'inline-start' | 'inline-end' | 'left' | 'right'Defaultbottom- The edge of the control the popup opens from.
align'start' | 'center' | 'end'Defaultstart- The alignment of the popup along that edge.
width'anchor' | 'content'Defaultcontent- The popup width: content keeps it at least as wide as the control and widens it to its longest option; anchor pins it to the width of the control.
mount'active' | 'lazy' | 'eager'Defaultactive- When the popup exists in the DOM: only while open, from the first open, or from the start.
strategy'absolute' | 'fixed'Defaultabsolute- The CSS positioning the popup uses.
clearablebooleanDefaulttrue- Whether a clear button appears once the input holds text.
loopbooleanDefaultfalse- Whether ArrowDown and ArrowUp wrap at the ends of the list.
closeOnSelectbooleanDefaulttrue- Whether choosing an option closes the popup.
closeOnEscapebooleanDefaulttrue- Whether Escape closes the popup.
closeOnOutsidePressbooleanDefaulttrue- Whether a press outside the combobox closes the popup.
flipbooleanDefaulttrue- Whether the popup moves to the opposite side when it does not fit.
shiftbooleanDefaulttrue- Whether the popup slides along its side to stay in view.
hideWhenDetachedbooleanDefaulttrue- Whether the popup hides once the control scrolls out of view.
portalbooleanDefaulttrue- Whether the popup renders at the end of the document instead of inside the combobox.
fullWidthbooleanDefaulttrue- Whether the control fills its container or keeps its own width.
disabledbooleanDefaultfalse- Turns off the input, the trigger and the popup. Unset follows the enclosing field.
readOnlybooleanDefaultfalse- Keeps the text selectable and copyable and never opens the popup. Unset follows the enclosing field.
requiredbooleanDefaultfalse- Sets the native required attribute on the input. Unset follows the enclosing field.
invalidbooleanDefaultfalse- Draws the border and the focus ring in the invalid tone and sets aria-invalid. Unset follows the enclosing field.
loadingbooleanDefaultfalse- Shows the spinner, the placeholder rows and the loading message, and sets aria-busy on the listbox.
sideOffsetnumberDefault4- The gap between the control and the popup, in pixels.
alignOffsetnumberDefault0- How far the popup shifts along its side, in pixels.
collisionPaddingnumberDefault8- The minimum distance between the popup and the edge of the viewport, in pixels.
messagesPartial<ComboboxMessages>- Phrases that replace the active locale’s, key by key: clear, trigger, create ({query}), empty, loading and count ({count}).
emptyReactNode- On ComboboxContentReplaces the empty message for this popup.
statusReactNode- On ComboboxContentReplaces the message in the status row for this popup.
valuestring- On ComboboxItemThe option key: what the form submits and what onValueChange receives.
disabledbooleanDefaultfalse- On ComboboxItemKeeps the option in the list, announces it as unavailable, and skips it with every movement key.
textValuestring- On ComboboxItemThe text the filter compares and the mark splits, when the children are not a string.
descriptionReactNode- On ComboboxItemThe second line under the label.
iconReactNode- On ComboboxItemThe element in the first column.
positionnumber- On ComboboxItemThe position of the option in the whole collection, written to aria-posinset.
labelReactNode- On ComboboxGroupThe name of the group, which the group references through aria-labelledby.
Events
| Name | Payload | When |
|---|---|---|
onInputValueChange | (value: string, request: ChangeRequest) | Before the text changes. The reason is keyboard while the reader types, select when an option is chosen, and clear, blur or programmatic otherwise. |
onValueChange | (value: string | null, request: ChangeRequest) | Before the chosen value changes. Typing calls only onInputValueChange; choosing an option calls both, each with the reason select. |
onOpenChange | (open: boolean, request: ChangeRequest) | Before the popup opens or closes. The reason tells a selection from a dismissal: select, escape, outsidePress, dismiss, blur, pointer, keyboard or programmatic. |
onHighlightedValueChange | (value: string | null, request: ChangeRequest) | Before the highlight moves, by key or by pointer, and when the filter removes the highlighted option. |
onCreate | (query: string, details: { reason, source? }) | When the reader takes the create option, which appears while onCreate is set, the query is not empty and nothing matched. The popup closes and nothing is selected: add the option to your collection and select it. |
onInputReset | (rejected: string, details: { reason: 'blur', source? }) | When the input loses focus holding text that matches no option while allowsCustomValue is off. The text returns to the label of the chosen option, or empties, and the handler receives the rejected text. |
onLoadMore | () | When the end of the rendered list scrolls into view. Fetch the next page; the combobox keeps no cursor of its own. |
Composition
ComboboxDefaultsProvidercomponent- On ApplicationSets any axis once for a subtree. The phrases come from the active locale, set by SlottedProvider.
render(props) => ReactNode- On ComboboxInput, ComboboxContentReplaces the frame around the input, or the popup layer. The input and the listbox carry the role and the ARIA wiring, so they cannot be replaced.
refRef<ComboboxHandle>- focus(), open(), close() and scrollToKey(value), for actions a prop cannot express.
refRef<HTMLInputElement>- On ComboboxInputThe input element, for code that reads the caret or the selection.
native propsComponentPropsWithRef<…>- On every partEach part accepts the props of its element. Your onKeyDown, placeholder, maxLength or aria-label reaches that element, and the combobox handler runs alongside yours instead of replacing it.
Parts
| Part | Element | Required | Purpose |
|---|---|---|---|
root | div, rendered by ComboboxInput | Yes | The visible frame, carrying data-ui="combobox". It draws the border, the shadow, the focus ring and every state, from the same tokens as the text field and the select. |
input | input with role="combobox" | Yes | A native text input, so the caret, the selection, IME, autofill and every text-editing key behave as in any input. It keeps focus for the whole interaction and carries aria-autocomplete, aria-expanded and aria-activedescendant. |
trigger | button | Yes | Opens and closes the popup with the pointer. It has tabindex="-1", as the ARIA combobox pattern requires, so Tab reaches the input once and skips the button. |
arrow | span | Yes | The chevron inside the trigger, a Glyph inside an Icon, turned over while the popup is open. |
busy | span | No | The spinner that replaces the chevron while loading is set, because the chevron promises a list that has not arrived. It carries data-ui="spinner" beside this part, so the spinner stylesheet draws the ring and the combobox sets only its place and size. |
clear | button | No | Resets both the text and the chosen value. Present only while clearable is set and the input holds text. |
positioner | div, rendered by ComboboxContent | Yes | The popup layer, portalled to the end of the document. It carries data-ui="combobox" again, because a stylesheet scoped to the root cannot reach a subtree outside it. |
content | div with role="listbox" | Yes | The popup surface, holding the options that pass the filter. Its height is bounded by the space the positioner reports, and it scrolls inside that bound. |
group | div with role="group" | No | A named set of options. A group whose options were all filtered away renders nothing, so no heading appears without options under it. |
group-label | div | No | The name of a group, which the group references through aria-labelledby. |
item | div with role="option" | Yes | One option. It compares its own label against the query and renders nothing when it does not match. |
indicator | span | Yes | The check in the last column, shown on the chosen option. |
icon | span | No | The first column: an Icon holding a Glyph, or any element of your own. |
label | span | Yes | The option text. It wraps to two lines and then truncates, with the whole text still in the DOM. |
match | mark | No | The part of the label the query matched, found with the same collator the filter used. It shows the reader why the option is in the results. |
description | span | No | A second line under the label, for detail the label has no room for. |
separator | div with role="separator" | No | A line between two runs of options. |
empty | div | No | The message the popup shows when nothing matched, instead of an empty box. |
status | div with role="status" and aria-live="polite" | Yes | The loading message and the live region in one row, so a screen reader user hears how many options matched. |
placeholder | div | No | Three rows the height of an option, drawn with the skeleton stylesheet while loading is set, so the popup already has the shape of the list. Hidden from assistive technology, because the status row announces the wait. |
Theming
Each token is a CSS custom property: set it in a theme, or on any element to retune every combobox inside it.
Combobox tokens
| Token | Default |
|---|---|
--slotted-combobox-action-active-background | var(--slotted-tone-secondary-subtle-active) |
--slotted-combobox-action-color | var(--slotted-text-muted, GrayText) |
--slotted-combobox-action-hover-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-combobox-action-size | min(calc(var(--_icon-size) + 2 * var(--slotted-space-2, 0.25rem)), var(--_inner-size)) |
--slotted-combobox-arrow-color | var(--slotted-text-muted, GrayText) |
--slotted-combobox-autofill-background | var(--slotted-tone-accent-surface) |
--slotted-combobox-background | var(--slotted-control-surface, Field) |
--slotted-combobox-border-color | var(--slotted-control-border-color, ButtonBorder) |
--slotted-combobox-color | var(--slotted-text, CanvasText) |
--slotted-combobox-completion-background | var(--slotted-tone-accent-surface) |
--slotted-combobox-completion-color | var(--slotted-tone-accent-text) |
--slotted-combobox-content-backdrop-filter | none |
--slotted-combobox-content-border-color | var(--slotted-border-subtle, #e2e8f0) |
--slotted-combobox-content-padding-block | var(--slotted-space-2, 0.25rem) |
--slotted-combobox-content-padding-inline | var(--slotted-space-2, 0.25rem) |
--slotted-combobox-content-radius | var(--slotted-radius-lg, 8px) |
--slotted-combobox-content-shadow | var(--slotted-shadow-md) |
--slotted-combobox-content-text | var(--slotted-text, #0f172a) |
--slotted-combobox-content-text-muted | var(--slotted-text-muted, #5b6b7f) |
--slotted-combobox-disabled-background | var(--slotted-disabled-background) |
--slotted-combobox-disabled-border-color | var(--slotted-disabled-border) |
--slotted-combobox-disabled-color | var(--slotted-disabled-foreground) |
--slotted-combobox-group-label-height | calc( var(--_secondary-font-size) * var(--slotted-line-height-sm, 1.45) + 2 * var(--slotted-space-2, 0.25rem) ) |
--slotted-combobox-highlight | var(--slotted-tone-secondary-subtle-active) |
--slotted-combobox-highlight-active | var(--slotted-tone-accent-surface) |
--slotted-combobox-highlight-ring | var(--slotted-tone-accent-border) |
--slotted-combobox-hover-border-color | var(--slotted-tone-accent-border) |
--slotted-combobox-icon-size-min | 14px |
--slotted-combobox-invalid-border-color | var(--slotted-tone-danger-border) |
--slotted-combobox-invalid-edge-width | var(--slotted-control-invalid-edge-width, 1px) |
--slotted-combobox-invalid-focus-ring-color | var(--slotted-focus-ring-color-invalid, Highlight) |
--slotted-combobox-item-radius | max(0px, calc(var(--_radius) - var(--_inset-inline))) |
--slotted-combobox-measure | 24rem |
--slotted-combobox-open-border-color | var(--slotted-tone-accent-border) |
--slotted-combobox-placeholder-color | var(--slotted-text-muted, GrayText) |
--slotted-combobox-plain-hover-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-combobox-radius | var(--slotted-control-radius, 4px) |
--slotted-combobox-readonly-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-combobox-selected-color | var(--slotted-tone-accent-text) |
--slotted-combobox-separator-color | var(--_border-color) |
--slotted-combobox-shadow | var(--slotted-control-shadow, none) |
--slotted-combobox-subtle-background | var(--slotted-surface-sunken, Canvas) |
--slotted-combobox-subtle-border-color | var(--slotted-border-subtle, ButtonBorder) |
--slotted-combobox-subtle-hover-background | var(--slotted-tone-secondary-subtle-hover) |
--slotted-combobox-surface | var(--slotted-surface-raised, #ffffff) |
Theme tokens it reads
| Token | Default |
|---|---|
--slotted-border-subtle | Set per scheme by the theme |
--slotted-border-width-thin | 1px |
--slotted-control-border-color | Set per scheme by the theme |
--slotted-control-border-width | var(--slotted-border-width-thin) |
--slotted-control-focus-ring-offset | var(--slotted-focus-ring-offset) |
--slotted-control-font-family | var(--slotted-font-family-sans) |
--slotted-control-font-size-lg | comfortable 14px · compact 13px · dense 12px |
--slotted-control-font-size-md | comfortable 13px · compact 12px · dense 12px |
--slotted-control-font-size-sm | comfortable 12px · compact 12px · dense 12px |
--slotted-control-gap-lg | comfortable 8px · compact 6px · dense 6px |
--slotted-control-gap-md | comfortable 8px · compact 6px · dense 4px |
--slotted-control-gap-sm | comfortable 6px · compact 4px · dense 4px |
--slotted-control-height-lg | comfortable 38px · compact 32px · dense 30px |
--slotted-control-height-md | comfortable 34px · compact 28px · dense 26px |
--slotted-control-height-sm | comfortable 30px · compact 26px · dense 24px |
--slotted-control-icon-size-lg | comfortable 18px · compact 16px · dense 14px |
--slotted-control-icon-size-md | comfortable 16px · compact 14px · dense 13px |
--slotted-control-icon-size-sm | comfortable 14px · compact 13px · dense 12px |
--slotted-control-inner-size-lg | comfortable 28px · compact 24px · dense 22px |
--slotted-control-inner-size-md | comfortable 24px · compact 20px · dense 18px |
--slotted-control-inner-size-sm | comfortable 22px · compact 18px · dense 16px |
--slotted-control-invalid-edge-width | var(--slotted-border-width-thin) |
--slotted-control-padding-inline-lg | comfortable 16px · compact 12px · dense 10px |
--slotted-control-padding-inline-md | comfortable 13px · compact 10px · dense 8px |
--slotted-control-padding-inline-sm | comfortable 10px · compact 8px · dense 6px |
--slotted-control-radius | var(--slotted-radius-sm) |
--slotted-control-shadow | Set per scheme by the theme |
--slotted-control-shadow-focus-geometry | 0 1px 4px -1px |
--slotted-control-surface | Set per scheme by the theme |
--slotted-control-transition-duration | var(--slotted-duration-short) |
--slotted-control-transition-easing | var(--slotted-easing-standard) |
--slotted-disabled-background | Set per scheme by the theme |
--slotted-disabled-border | Set per scheme by the theme |
--slotted-disabled-foreground | Set per scheme by the theme |
--slotted-duration-medium | 200ms |
--slotted-duration-short | 120ms |
--slotted-easing-enter | cubic-bezier(0.05, 0.7, 0.1, 1) |
--slotted-easing-exit | cubic-bezier(0.3, 0, 0.8, 0.15) |
--slotted-easing-standard | cubic-bezier(0.2, 0, 0, 1) |
--slotted-focus-ring-color | Set per scheme by the theme |
--slotted-focus-ring-color-invalid | Set per scheme by the theme |
--slotted-focus-ring-offset | var(--slotted-border-width-thick) |
--slotted-focus-ring-width | var(--slotted-border-width-thick) |
--slotted-font-family-sans | 'Geist Variable', ui-sans-serif, system-ui, sans-serif |
--slotted-font-size-xs | 0.75rem |
--slotted-font-weight-medium | 500 |
--slotted-font-weight-semibold | 600 |
--slotted-line-height-md | 1.5 |
--slotted-line-height-sm | 1.45 |
--slotted-overlay-max-block-size | 100vh |
--slotted-radius-lg | 8px |
--slotted-radius-none | 0px |
--slotted-shadow-md | Set per scheme by the theme |
--slotted-space-1 | 0.125rem |
--slotted-space-2 | 0.25rem |
--slotted-space-5 | 0.75rem |
--slotted-surface-raised | Set per scheme by the theme |
--slotted-surface-sunken | Set per scheme by the theme |
--slotted-target-comfortable | 44px |
--slotted-target-min | 24px |
--slotted-text | Set per scheme by the theme |
--slotted-text-muted | Set per scheme by the theme |
--slotted-tone-accent-border | Set per scheme by the theme |
--slotted-tone-accent-surface | Set per scheme by the theme |
--slotted-tone-accent-text | Set per scheme by the theme |
--slotted-tone-danger-border | Set per scheme by the theme |
--slotted-tone-secondary-subtle-active | Set per scheme by the theme |
--slotted-tone-secondary-subtle-hover | Set per scheme by the theme |
--slotted-z-index-popover | 1100 |