Select
Single selection from a list of options, with groups, typeahead and native form serialisation.
Purpose
Select chooses one value from a short list. It renders a button that opens a listbox, and submits
its value with forms through name.
Import
import { Select } from "@neshel-ui/components";Usage
Choose a region.
import { Label, Select, type SelectOptions } from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
import { Caption } from "@neshel-ui/typography";
const countries: SelectOptions = [
{ value: "cr", label: "Costa Rica" },
{ value: "es", label: "Spain" },
{ value: "jp", label: "Japan" },
{ value: "ca", label: "Canada", disabled: true },
];
const languages: SelectOptions = [
{
label: "Europe",
options: [
{ value: "es", label: "Spanish" },
{ value: "fr", label: "French" },
],
},
{
label: "Asia",
options: [
{ value: "ja", label: "Japanese" },
{ value: "ko", label: "Korean" },
],
},
];
export default function SelectBasic() {
return (
<Stack space="5" className="max-w-sm">
<Stack space="2">
<Label htmlFor="select-country">Country</Label>
<Select
id="select-country"
name="country"
options={countries}
placeholder="Select a country"
/>
</Stack>
<Stack space="2">
<Label htmlFor="select-language">Language (grouped)</Label>
<Select id="select-language" name="language" options={languages} defaultValue="fr" />
</Stack>
<Stack space="2">
<Label htmlFor="select-required">Region</Label>
<Select
id="select-required"
options={countries}
invalid
aria-describedby="select-required-error"
placeholder="Required"
/>
<Caption id="select-required-error" tone="destructive">
Choose a region.
</Caption>
</Stack>
</Stack>
);
}API
SelectProps
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-describedby | string | — | — |
| aria-label | string | — | — |
| aria-labelledby | string | — | — |
| className | string | — | — |
| container | HTMLElement | null | — | Portal target for the popup (default: the enclosing Neshel overlay, else document.body). |
| defaultOpen | boolean | — | — |
| defaultValue | string | null | — | Initial selected value when uncontrolled. |
| disabled | boolean | — | — |
| form | string | — | — |
| id | string | — | Id of the focusable control; associate a <Label htmlFor> with it. |
| invalid | boolean | — | Marks the control aria-invalid. Describe the error with aria-describedby. |
| name | string | — | Form field name; one entry per selected value. |
| onOpenChange | (open: boolean) => void | — | — |
| onValueChange | (value: string | null) => void | — | Called with the new value. |
| open | boolean | — | — |
| options(required) | SelectOptions | — | Options, flat or grouped. |
| placeholder | string | — | Text shown when nothing is selected. |
| readOnly | boolean | — | — |
| ref | Ref<HTMLButtonElement> | — | — |
| required | boolean | — | — |
| uiSize | FieldSize | "md" | Field size (default "md"). |
| value | string | null | — | Controlled selected value (null = none). |
SelectFieldProps
Props shared by Select, MultiSelect and Combobox.
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-describedby | string | — | — |
| aria-label | string | — | — |
| aria-labelledby | string | — | — |
| className | string | — | — |
| container | HTMLElement | null | — | Portal target for the popup (default: the enclosing Neshel overlay, else document.body). |
| defaultOpen | boolean | — | — |
| disabled | boolean | — | — |
| form | string | — | — |
| id | string | — | Id of the focusable control; associate a <Label htmlFor> with it. |
| invalid | boolean | — | Marks the control aria-invalid. Describe the error with aria-describedby. |
| name | string | — | Form field name; one entry per selected value. |
| onOpenChange | (open: boolean) => void | — | — |
| open | boolean | — | — |
| placeholder | string | — | Text shown when nothing is selected. |
| readOnly | boolean | — | — |
| required | boolean | — | — |
| uiSize | FieldSize | "md" | Field size (default "md"). |
SelectOption
| 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. |
SelectOptionGroup
| Prop | Type | Default | Description |
|---|---|---|---|
| label(required) | string | — | Visible text (also used for typeahead and chips). |
| options(required) | readonly SelectOption[] | — | Options of the group. |
SelectOptions
Also accepts the props of: typescript.
SelectFieldProps are shared by Select, MultiSelect and Combobox.
Controlled and uncontrolled
"use client";
import { Label, Select } from "@neshel-ui/components";
import { Stack } from "@neshel-ui/layout";
import { Text } from "@neshel-ui/typography";
import { useState } from "react";
const plans = [
{ value: "free", label: "Free" },
{ value: "team", label: "Team" },
{ value: "enterprise", label: "Enterprise" },
];
export default function SelectControlled() {
const [plan, setPlan] = useState<string | null>("team");
return (
<Stack space="2" className="max-w-sm">
<Label htmlFor="select-plan">Plan</Label>
<Select id="select-plan" options={plans} value={plan} onValueChange={setPlan} />
<Text tone="muted" size="sm">
value: {String(plan)}
</Text>
</Stack>
);
}- Uncontrolled:
defaultValue(or nothing, showingplaceholder). - Controlled:
value(string | null) +onValueChange. open/defaultOpen/onOpenChangecontrol the popup.
Forms
With name, the selected value is submitted as one form entry. required, disabled, readOnly and
form behave like native attributes. invalid marks the control (aria-invalid).
Accessibility
- Label it with
<Label htmlFor={id}>, oraria-label/aria-labelledby. - The trigger is a
comboboxthat controls alistbox; options announce their selected state. - Describe errors with
aria-describedby.
Keyboard
| Key | Action |
|---|---|
| Enter / Space / ↓ / ↑ | Open the listbox |
| ↓ / ↑, Home / End | Move between options |
| Type letters | Jump to the matching option (typeahead) |
| Enter / Space | Select and close |
| Escape | Close without changing the value |
Styling
uiSize (sm md lg) matches Input heights. The popup layer is --neshel-z-popover; selected options
use --neshel-selected.
Common mistakes
- More than ~15 options: users need search — use Combobox.
- Non-string values: values are strings; map your objects to ids.