ComboBox
A text input that filters a dropdown list of options as you type.
View in Storybook (opens in a new tab)
Installation
import { ComboBox } from "@ginga-ui/core";Basic usage
Place ComboBoxItem elements inside. Typing filters the options.
combo-box.tsx
import { ComboBox, ComboBoxItem } from "@ginga-ui/core";
import { Check, ChevronDown } from "lucide-react";
export function BasicExample() {
return (
<ComboBox
label="Prefecture"
placeholder="Type to filter"
icon={<ChevronDown />}
checkIcon={<Check />}
>
{PREFECTURES.map((p) => (
<ComboBoxItem key={p.id} id={p.id}>
{p.name}
</ComboBoxItem>
))}
</ComboBox>
);
}Validation
Use description for help text and errorMessage for the message shown when the value is invalid.
Choose the prefecture for delivery
combo-box.tsx
import { ComboBox, ComboBoxItem } from "@ginga-ui/core";
import { ChevronDown } from "lucide-react";
export function ValidationExample() {
return (
<ComboBox
label="Prefecture"
description="Choose the prefecture for delivery"
errorMessage="Choose a prefecture"
required
icon={<ChevronDown />}
>
{PREFECTURES.map((p) => (
<ComboBoxItem key={p.id} id={p.id}>
{p.name}
</ComboBoxItem>
))}
</ComboBox>
);
}Disabled
Pass disabled to disable the whole combo box.
combo-box.tsx
import { ComboBox, ComboBoxItem } from "@ginga-ui/core";
import { ChevronDown } from "lucide-react";
export function DisabledExample() {
return (
<ComboBox
label="Prefecture"
disabled
defaultSelectedKey="osaka"
icon={<ChevronDown />}
>
{PREFECTURES.map((p) => (
<ComboBoxItem key={p.id} id={p.id}>
{p.name}
</ComboBoxItem>
))}
</ComboBox>
);
}Props
ComboBox
| Name | Type | Default | Description |
|---|---|---|---|
label | string | - | Label shown above the combo box. |
placeholder | string | - | Placeholder text of the input. |
description | ReactNode | - | Help text shown below the combo box. |
errorMessage | ReactNode | ((validation: ValidationResult) => ReactNode) | - | Error message shown when the value is invalid. |
disabled | boolean | false | Disables the combo box. |
required | boolean | false | Requires a value. |
readOnly | boolean | false | Makes the combo box read-only. |
invalid | boolean | false | Shows the combo box as invalid. |
children | ReactNode | - | ComboBoxItem elements. |
icon | ReactNode | - | Icon shown in the button that opens the list. A chevron is drawn when omitted. |
checkIcon | ReactNode | - | Icon shown next to the selected item. |
Also accepts the props of React Aria's ComboBox (opens in a new tab).
ComboBoxItem
| Name | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables the item. |
textValue | string | children (string only) | Text used for filtering and screen readers. Required when children is not a string. |
Also accepts the props of React Aria's ListBoxItem (opens in a new tab).