Combobox
Combobox is a text field with a list of options under it. The list narrows
as you type. Type “j”, then use the arrow keys and Enter, or click an option:
Chosen: nothing yet
import { Paragraph, View } from '@hozo/core'import { Combobox } from '@hozo/ui'import { useState } from 'react'
const COUNTRIES = [ { value: 'jp', label: 'Japan' }, { value: 'jm', label: 'Jamaica' }, { value: 'jo', label: 'Jordan' }, { value: 'ke', label: 'Kenya' }, { value: 'kr', label: 'South Korea' }, { value: 'nz', label: 'New Zealand' },]
export function ComboboxDemo() { const [country, setCountry] = useState<string>() return ( <View className="w-full max-w-xs gap-3"> <Combobox options={COUNTRIES} accessibilityLabel="Country" placeholder="Type a country" value={country} onValueChange={setCountry} /> <Paragraph className="text-sm text-hozo-text-body"> {`Chosen: ${country ?? 'nothing yet'}`} </Paragraph> </View> )}options:{ value, label, disabled? }for each option.valueandonValueChangehold the chosen option’s value.- Focus stays in the field. The arrows move a highlight through the list
with
aria-activedescendant, so typing can carry on at any moment. Enter chooses the highlighted option, and Escape closes the list. matchisstartsby default, orcontainsto match anywhere in a label.autocompleteislistby default, which filters the list.bothalso completes the rest of the first match inline, andnoneshows every option.emptyMessageis shown when nothing matches.accessibilityLabelnames the field.placeholderis a hint inside it, not a label.