Combo box with search min length
The search has a minLength of 2. No results will show until 2 characters are typed.
import { useState } from 'react';
import { ComboBox, useTokenSearch } from '@citizensadvice/react-combo-boxes';
const options = ['Apple', 'Banana', 'Orange'];
export function Example() {
const [value, setValue] = useState();
const [search, setSearch] = useState(null);
const filteredOptions = useTokenSearch(search, { options, minLength: 2 });
return (
<>
<label
id="select-label"
htmlFor="select"
>
Select
</label>
<ComboBox
id="select"
aria-labelledby="select-label"
value={value}
onValue={setValue}
onSearch={setSearch}
options={filteredOptions}
/>
<label htmlFor="output">Current value</label>
<output
htmlFor="select"
id="output"
>
{JSON.stringify(value, undefined, ' ')}
</output>
</>
);
}