Skip to Content
Neshel-UI
Components

Select

Single selection from a list of options, with groups, typeahead and native form serialisation.

Client component ("use client")

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.tsx
import { Select } from "@neshel-ui/components";

Usage

Preview: select-basic
Preview theme

Choose a region.

select-basic.tsx
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

SelectProps
PropTypeDefaultDescription
aria-describedbystring——
aria-labelstring——
aria-labelledbystring——
classNamestring——
containerHTMLElement | null—Portal target for the popup (default: the enclosing Neshel overlay, else document.body).
defaultOpenboolean——
defaultValuestring | null—Initial selected value when uncontrolled.
disabledboolean——
formstring——
idstring—Id of the focusable control; associate a <Label htmlFor> with it.
invalidboolean—Marks the control aria-invalid. Describe the error with aria-describedby.
namestring—Form field name; one entry per selected value.
onOpenChange(open: boolean) => void——
onValueChange(value: string | null) => void—Called with the new value.
openboolean——
options(required)SelectOptions—Options, flat or grouped.
placeholderstring—Text shown when nothing is selected.
readOnlyboolean——
refRef<HTMLButtonElement>——
requiredboolean——
uiSizeFieldSize"md"Field size (default "md").
valuestring | null—Controlled selected value (null = none).

SelectFieldProps

Props shared by Select, MultiSelect and Combobox.

SelectFieldProps
PropTypeDefaultDescription
aria-describedbystring——
aria-labelstring——
aria-labelledbystring——
classNamestring——
containerHTMLElement | null—Portal target for the popup (default: the enclosing Neshel overlay, else document.body).
defaultOpenboolean——
disabledboolean——
formstring——
idstring—Id of the focusable control; associate a <Label htmlFor> with it.
invalidboolean—Marks the control aria-invalid. Describe the error with aria-describedby.
namestring—Form field name; one entry per selected value.
onOpenChange(open: boolean) => void——
openboolean——
placeholderstring—Text shown when nothing is selected.
readOnlyboolean——
requiredboolean——
uiSizeFieldSize"md"Field size (default "md").

SelectOption

SelectOption
PropTypeDefaultDescription
disabledboolean——
label(required)string—Visible text (also used for typeahead and chips).
value(required)string—Value submitted with the form and passed to onValueChange.

SelectOptionGroup

SelectOptionGroup
PropTypeDefaultDescription
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

Preview: select-controlled
Preview theme
value: team
select-controlled.tsx
"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, showing placeholder).
  • Controlled: value (string | null) + onValueChange.
  • open / defaultOpen / onOpenChange control 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}>, or aria-label / aria-labelledby.
  • The trigger is a combobox that controls a listbox; options announce their selected state.
  • Describe errors with aria-describedby.

Keyboard

KeyAction
Enter / Space / ↓ / ↑Open the listbox
↓ / ↑, Home / EndMove between options
Type lettersJump to the matching option (typeahead)
Enter / SpaceSelect and close
EscapeClose 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.
Edit on GitHub

On this page