Components
Combobox
A filterable text input for single or multiple selection, with groups and external filtering.
Client component ("use client")
import.tsx
combobox-single.tsx
combobox-multiple.tsx
combobox-async.tsx
Edit on GitHubPurpose
Combobox lets users type to filter a list and pick one value (default) or several (multiple).
The value is always one of the items — it is not a free-text input.
Import
import { Combobox } from "@neshel-ui/components";Single mode
Preview: combobox-single
import { Combobox, Label } from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
const destinations = [
{
label: "Americas",
items: [
{ value: "cr", label: "Costa Rica" },
{ value: "pe", label: "Peru" },
{ value: "ca", label: "Canada" },
],
},
{
label: "Europe",
items: [
{ value: "es", label: "Spain" },
{ value: "pt", label: "Portugal" },
],
},
{
label: "Asia",
items: [
{ value: "jp", label: "Japan" },
{ value: "vn", label: "Vietnam" },
],
},
];
export default function ComboboxSingle() {
return (
<Stack space="2" className="max-w-sm">
<Label htmlFor="combobox-destination">Destination</Label>
<Combobox
id="combobox-destination"
name="destination"
items={destinations}
placeholder="Search a country"
/>
</Stack>
);
}Multiple mode
Preview: combobox-multiple
TypeScript
import { Combobox, Label } from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
const technologies = [
{ value: "ts", label: "TypeScript" },
{ value: "rs", label: "Rust" },
{ value: "go", label: "Go" },
{ value: "py", label: "Python" },
{ value: "kt", label: "Kotlin" },
];
export default function ComboboxMultiple() {
return (
<Stack space="2" className="max-w-md">
<Label htmlFor="combobox-tech">Technologies</Label>
<Combobox
id="combobox-tech"
name="technologies"
multiple
items={technologies}
defaultValue={["ts"]}
placeholder="Select technologies"
/>
</Stack>
);
}External filtering (server search)
Pass filter={null}, update items from onInputValueChange, and set loading while fetching.
Selected chips keep their labels when the results change.
Preview: combobox-async
value: []
"use client";
import { Combobox, Label } from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
import { Text } from "@neshel-ui/typography";
import { useEffect, useState } from "react";
const catalogue = [
{ value: "ts", label: "TypeScript" },
{ value: "rs", label: "Rust" },
{ value: "go", label: "Go" },
{ value: "py", label: "Python" },
{ value: "kt", label: "Kotlin" },
{ value: "sw", label: "Swift" },
];
/** External filtering: the application owns the items (here a simulated request). */
export default function ComboboxAsync() {
const [query, setQuery] = useState("");
const [items, setItems] = useState(catalogue);
const [loading, setLoading] = useState(false);
const [value, setValue] = useState<string[]>([]);
useEffect(() => {
setLoading(true);
const timer = setTimeout(() => {
setItems(catalogue.filter((item) => item.label.toLowerCase().includes(query.toLowerCase())));
setLoading(false);
}, 400);
return () => clearTimeout(timer);
}, [query]);
return (
<Stack space="2" className="max-w-md">
<Label htmlFor="combobox-async">Technologies (server search)</Label>
<Combobox
id="combobox-async"
multiple
items={items}
filter={null}
loading={loading}
inputValue={query}
onInputValueChange={setQuery}
value={value}
onValueChange={setValue}
placeholder="Type to search"
/>
<Text tone="muted" size="sm">
value: {JSON.stringify(value)}
</Text>
</Stack>
);
}API
ComboboxProps
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-describedby | string | — | — |
| aria-label | string | — | — |
| aria-labelledby | string | — | — |
| className | string | — | — |
| clearLabel | string | "Clear selection" | Accessible name of the clear button (default "Clear selection"). |
| clearable | boolean | true | Show a clear button when a value is selected (default true). |
| container | HTMLElement | null | — | Portal target for the popup (default: the enclosing Neshel overlay, else document.body). |
| defaultInputValue | string | — | Initial text of the input when uncontrolled. |
| defaultOpen | boolean | — | — |
| defaultValue | string | null | readonly string[] | — | Initial selected value when uncontrolled. |
| disabled | boolean | — | — |
| emptyMessage | ReactNode | "No results" | Shown when no item matches (default "No results"). |
| filter | ((item: ComboboxItem, query: string) => boolean) | null | — | Local filter (default: case-insensitive label match); null when the app filters items. |
| form | string | — | — |
| id | string | — | Id of the focusable control; associate a <Label htmlFor> with it. |
| inputValue | string | — | Controlled text of the input. |
| invalid | boolean | — | Marks the control aria-invalid. Describe the error with aria-describedby. |
| items(required) | readonly ComboboxItem[] | readonly ComboboxItemGroup[] | — | Items, or groups of items (not mixed). |
| loading | boolean | — | Shows loadingMessage while external results load. |
| loadingMessage | ReactNode | "Loading…" | Loading text (default "Loading…"). |
| multiple | boolean | — | Single selection (default). |
| name | string | — | Form field name; one entry per selected value. |
| onInputValueChange | (value: string) => void | — | Called when the user types; use with filter={null} for server-side search. |
| onOpenChange | (open: boolean) => void | — | — |
| onValueChange | (value: string | null) => void | (value: string[]) => void | — | Called with the new value (null when cleared). |
| open | boolean | — | — |
| placeholder | string | — | Text shown when nothing is selected. |
| readOnly | boolean | — | — |
| ref | Ref<HTMLInputElement> | — | — |
| removeLabel | (label: string) => string | Remove <label> | Accessible name of a chip's remove button (default: Remove <label>). |
| required | boolean | — | — |
| triggerLabel | string | "Show options" | Accessible name of the button that opens the list (default "Show options"). |
| uiSize | FieldSize | "md" | Field size (default "md"). |
| value | string | null | readonly string[] | — | Controlled selected value (null = none). |
ComboboxSingleProps
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-describedby | string | — | — |
| aria-label | string | — | — |
| aria-labelledby | string | — | — |
| className | string | — | — |
| clearLabel | string | "Clear selection" | Accessible name of the clear button (default "Clear selection"). |
| clearable | boolean | true | Show a clear button when a value is selected (default true). |
| container | HTMLElement | null | — | Portal target for the popup (default: the enclosing Neshel overlay, else document.body). |
| defaultInputValue | string | — | Initial text of the input when uncontrolled. |
| defaultOpen | boolean | — | — |
| defaultValue | string | null | — | Initial selected value when uncontrolled. |
| disabled | boolean | — | — |
| emptyMessage | ReactNode | "No results" | Shown when no item matches (default "No results"). |
| filter | ((item: ComboboxItem, query: string) => boolean) | null | — | Local filter (default: case-insensitive label match); null when the app filters items. |
| form | string | — | — |
| id | string | — | Id of the focusable control; associate a <Label htmlFor> with it. |
| inputValue | string | — | Controlled text of the input. |
| invalid | boolean | — | Marks the control aria-invalid. Describe the error with aria-describedby. |
| items(required) | readonly ComboboxItem[] | readonly ComboboxItemGroup[] | — | Items, or groups of items (not mixed). |
| loading | boolean | — | Shows loadingMessage while external results load. |
| loadingMessage | ReactNode | "Loading…" | Loading text (default "Loading…"). |
| multiple | false | — | Single selection (default). |
| name | string | — | Form field name; one entry per selected value. |
| onInputValueChange | (value: string) => void | — | Called when the user types; use with filter={null} for server-side search. |
| onOpenChange | (open: boolean) => void | — | — |
| onValueChange | (value: string | null) => void | — | Called with the new value (null when cleared). |
| open | boolean | — | — |
| placeholder | string | — | Text shown when nothing is selected. |
| readOnly | boolean | — | — |
| ref | Ref<HTMLInputElement> | — | — |
| required | boolean | — | — |
| triggerLabel | string | "Show options" | Accessible name of the button that opens the list (default "Show options"). |
| uiSize | FieldSize | "md" | Field size (default "md"). |
| value | string | null | — | Controlled selected value (null = none). |
ComboboxMultipleProps
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-describedby | string | — | — |
| aria-label | string | — | — |
| aria-labelledby | string | — | — |
| className | string | — | — |
| clearLabel | string | "Clear selection" | Accessible name of the clear button (default "Clear selection"). |
| clearable | boolean | true | Show a clear button when a value is selected (default true). |
| container | HTMLElement | null | — | Portal target for the popup (default: the enclosing Neshel overlay, else document.body). |
| defaultInputValue | string | — | Initial text of the input when uncontrolled. |
| defaultOpen | boolean | — | — |
| defaultValue | readonly string[] | — | Initial selected values when uncontrolled. |
| disabled | boolean | — | — |
| emptyMessage | ReactNode | "No results" | Shown when no item matches (default "No results"). |
| filter | ((item: ComboboxItem, query: string) => boolean) | null | — | Local filter (default: case-insensitive label match); null when the app filters items. |
| form | string | — | — |
| id | string | — | Id of the focusable control; associate a <Label htmlFor> with it. |
| inputValue | string | — | Controlled text of the input. |
| invalid | boolean | — | Marks the control aria-invalid. Describe the error with aria-describedby. |
| items(required) | readonly ComboboxItem[] | readonly ComboboxItemGroup[] | — | Items, or groups of items (not mixed). |
| loading | boolean | — | Shows loadingMessage while external results load. |
| loadingMessage | ReactNode | "Loading…" | Loading text (default "Loading…"). |
| multiple(required) | true | — | Multiple selection with removable chips. |
| name | string | — | Form field name; one entry per selected value. |
| onInputValueChange | (value: string) => void | — | Called when the user types; use with filter={null} for server-side search. |
| onOpenChange | (open: boolean) => void | — | — |
| onValueChange | (value: string[]) => void | — | Called with the new list of values. |
| open | boolean | — | — |
| placeholder | string | — | Text shown when nothing is selected. |
| readOnly | boolean | — | — |
| ref | Ref<HTMLInputElement> | — | — |
| removeLabel | (label: string) => string | Remove <label> | Accessible name of a chip's remove button (default: Remove <label>). |
| required | boolean | — | — |
| triggerLabel | string | "Show options" | Accessible name of the button that opens the list (default "Show options"). |
| uiSize | FieldSize | "md" | Field size (default "md"). |
| value | readonly string[] | — | Controlled selected values. |
ComboboxItem
| Prop | Type | Default | Description |
|---|---|---|---|
| disabled | boolean | — | — |
| label(required) | string | — | Visible text (also used for typeahead and chips). |
| value(required) | string | — | Value submitted with the form and passed to onValueChange. |
ComboboxItemGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| items(required) | readonly ComboboxItem[] | — | Items of the group. |
| label(required) | string | — | Group heading. |
ComboboxProps is the union of the single and multiple variants: with multiple, value is a
string[]; without it, string | null.
Controlled and uncontrolled
- Value:
value/defaultValue/onValueChange. - Input text:
inputValue/defaultInputValue/onInputValueChange. - Popup:
open/defaultOpen/onOpenChange.
Forms
With name, the selected value (or each value in multiple mode) is submitted.
Accessibility
- The input is a
comboboxcontrolling alistbox; the active option is announced as you move. emptyMessage("No results") andloadingMessage("Loading…") are announced in the popup.- Escape closes the popup and never clears the value; clear with the clear button or Backspace on chips.
- Inside a Dialog or Popover, the popup renders inside that overlay; Escape closes the popup first.
Keyboard
| Key | Action |
|---|---|
| Type | Filter the items (opens the popup) |
| ↓ / ↑ | Move between items |
| Enter | Select the active item |
| Escape | Close the popup |
| Backspace (empty input, multiple) | Remove the last chip |
Common mistakes
- Expecting free text: values must be items. For suggestions with free text, use
<Input list="…">and a<datalist>. - Filtering both locally and on the server: pass
filter={null}when the application filters.