"use client";
import { Combobox } from "@pixxl-tools/components";| Prop | Type | Default | Description |
|---|---|---|---|
options (required) | readonly ComboboxItem<Option>[] | — | Options and groups ({ label, options }). |
getOptionLabel | (option: Option) => string | — | Text of an option for the input and filtering (default: string label, textValue, value). |
getOptionValue | (option: Option) => string | option.value | Stable string key of an option (default option.value). |
inputLabel | string | from messages | Accessible name of the input (default from messages). |
onValueChange | (value: Value, option: Option | null) => void | — | Called with the new value (only when it changes). |
value | Value | — | Current value (controlled); null where it means "nothing selected". |
autoHighlight | boolean | true | Make the first matching option active while typing (default true). |
clearable | boolean | — | Show a clear button while there is a value or text. |
clearLabel | string | from the catalog | Accessible name of the clear button (default from the catalog). |
closeOnSelect | boolean | true | Close after a selection (default: true, false with multiple). |
optionsrequiredreadonly ComboboxItem<Option>[]
Options and groups ({ label, options }).
getOptionLabel(option: Option) => string
Text of an option for the input and filtering (default: string label, textValue, value).
getOptionValuedefault option.value(option: Option) => string
Stable string key of an option (default option.value).
inputLabeldefault from messagesstring
Accessible name of the input (default from messages).
onValueChange(value: Value, option: Option | null) => void
Called with the new value (only when it changes).
valueValue
Current value (controlled); null where it means "nothing selected".
autoHighlightdefault trueboolean
Make the first matching option active while typing (default true).
clearableboolean
Show a clear button while there is a value or text.
clearLabeldefault from the catalogstring
Accessible name of the clear button (default from the catalog).
closeOnSelectdefault trueboolean
Close after a selection (default: true, false with multiple).
Value: banana
const produce = [
{ label: "Fruit", options: [{ label: "Apple", value: "apple" }, { label: "Banana", value: "banana" }] },
{ label: "Vegetables", options: [{ label: "Carrot", value: "carrot" }, { label: "Leek", value: "leek" }] },
];
const [value, setValue] = useState("banana");
<Combobox inputLabel="Produce" options={produce} value={value} onValueChange={setValue} clearable />const groups = [
{ label: "Fruit", options: [{ label: "Apple", value: "apple" }, { label: "Banana", value: "banana" }] },
{ label: "Vegetables", options: [{ label: "Carrot", value: "carrot" }] },
];
const [values, setValues] = useState<string[]>([]);
<Combobox inputLabel="Produce" multiple options={groups} value={values} onValueChange={setValues} />Prefetch 0
Virtualization (500) 0
Pagination (first 20) 0
Infinite loading 0
Debounce (300 ms) 0
Lazy load on open 0
Memoized cache 0
Recent items 0
type User = { id: number; name: string };
// Your API: one page of users for a query.
async function searchUsers({ query, offset, pageSize, signal }: { query: string; offset: number; pageSize?: number; signal: AbortSignal }) {
const response = await fetch(`/api/users?q=${encodeURIComponent(query)}&offset=${offset}&limit=${pageSize ?? 20}`, { signal });
const page: { users: User[]; hasMore: boolean } = await response.json();
return { hasMore: page.hasMore, options: page.users };
}
const users = useAsyncOptions<User>({
loadOptions: (query, { signal, offset, pageSize }) => searchUsers({ query, offset, pageSize, signal }),
mode: "onOpen", // "prefetch" | "onOpen" | "onType"
debounceMs: 300,
cache: { ttl: 60_000, max: 50 },
pageSize: 20,
infinite: true, // false: "refine your search" hint when a page is full
});
const recent = useRecentOptions<User>({ storageKey: "recent-users", max: 5 });
<Combobox<User>
{...users.comboboxProps}
options={recent.group ? [recent.group, ...users.options] : users.options}
getOptionValue={(user) => String(user.id)}
getOptionLabel={(user) => user.name}
onValueChange={(value, user) => recent.addRecent(user)}
virtualize
clearable
/>