Select
A select box for choosing an item from a dropdown list.
View in Storybook (opens in a new tab)
Installation
import { Select } from "@ginga-ui/core";Basic usage
A simple select box example.
Favorite animal
select.tsx
import { Select, SelectItem } from "@ginga-ui/core";
import { Check, ChevronDown } from "lucide-react";
export function BasicExample() {
return (
<Select
icon={<ChevronDown />}
checkIcon={<Check />}
defaultSelectedKey="cat"
label="Favorite animal"
>
<SelectItem id="cat">Cat</SelectItem>
<SelectItem id="dog">Dog</SelectItem>
<SelectItem id="bird">Bird</SelectItem>
</Select>
);
}Disabled options
A select box with some options disabled.
Choose a pet
select.tsx
import { Select, SelectItem } from "@ginga-ui/core";
import { Check, ChevronDown } from "lucide-react";
export function DisabledOptionsExample() {
return (
<Select
icon={<ChevronDown />}
checkIcon={<Check />}
defaultSelectedKey="dog"
label="Choose a pet"
>
<SelectItem id="dog">Dog</SelectItem>
<SelectItem id="cat">Cat</SelectItem>
<SelectItem id="hamster" disabled>
Hamster (out of stock)
</SelectItem>
<SelectItem id="parrot">Parrot</SelectItem>
</Select>
);
}Disabled
An example of disabling the entire select box.
Favorite animal
select.tsx
import { Select, SelectItem } from "@ginga-ui/core";
import { Check, ChevronDown } from "lucide-react";
export function DisabledExample() {
return (
<Select
icon={<ChevronDown />}
checkIcon={<Check />}
disabled
defaultSelectedKey="cat"
label="Favorite animal"
>
<SelectItem id="cat">Cat</SelectItem>
<SelectItem id="dog">Dog</SelectItem>
<SelectItem id="bird">Bird</SelectItem>
</Select>
);
}Controlled select
A select box whose state is controlled externally.
Skill level
select.tsx
import { Select, SelectItem } from "@ginga-ui/core";
import { Check, ChevronDown } from "lucide-react";
export function ControlledExample() {
return (
<Select
icon={<ChevronDown />}
checkIcon={<Check />}
label="Skill level"
defaultSelectedKey="beginner"
onSelectionChange={(key) => console.log("Selected:", key)}
>
<SelectItem id="beginner">Beginner</SelectItem>
<SelectItem id="intermediate">Intermediate</SelectItem>
<SelectItem id="advanced">Advanced</SelectItem>
</Select>
);
}Props
Select
| Name | Type | Default | Description |
|---|---|---|---|
label | string | - | Required. Label shown above the select. |
children | ReactNode | - | SelectItem elements. |
description | ReactNode | - | Help text shown below the select. |
errorMessage | ReactNode | ((validation: ValidationResult) => ReactNode) | - | Error message shown when the value is invalid. |
disabled | boolean | false | Disables the select. |
required | boolean | false | Requires a selection. |
invalid | boolean | false | Shows the select as invalid. |
icon | ReactNode | - | Icon shown at the end of the button. |
checkIcon | ReactNode | - | Icon shown next to the selected item. |
Also accepts the props of React Aria's Select (opens in a new tab).
SelectItem
| Name | Type | Default | Description |
|---|---|---|---|
disabled | boolean | false | Disables the item. |
textValue | string | children (string only) | Text used for type-to-select and screen readers. Required when children is not a string. |
Also accepts the props of React Aria's ListBoxItem (opens in a new tab).