[ Forms ]
Select
A fully styled dropdown for picking one value from a list. Unlike the browser's native menu, every part is themed: options can have icons, descriptions and groups, the selected option gets a check mark, and the list follows your light/dark theme. It supports keyboard navigation and type-ahead, and submits with forms.
Import#
import { Select, NativeSelect } from 'reusify-ui';When to use#
- Choosing one option from a list of roughly 5 to 30 items.
- For 2 to 4 options, a RadioGroup shows every choice at once and is often faster.
- For actions (not values), use a Dropdown menu instead.
- Need the OS picker on mobile or register() from React Hook Form? Use NativeSelect (same field props, real <select>).
Examples#
Options & placeholder#
Pass options as { label, value, disabled? } objects. placeholder shows while nothing is selected. Open it to see the styled list; disabled options are skipped.
const countries = [
{ label: 'India', value: 'in' },
{ label: 'United States', value: 'us' },
{ label: 'United Kingdom', value: 'uk' },
{ label: 'Germany', value: 'de' },
{ label: 'Japan', value: 'jp', disabled: true },
];
<Select label="Country" placeholder="Choose a country" options={countries} />Controlled#
onChange receives the selected value directly (not an event), just like RadioGroup and Tabs.
Selected: us
const [country, setCountry] = useState('us');
<Select label="Country" value={country} onChange={setCountry} options={countries} />Icons & descriptions#
Each option can have an icon and a description. The selected option's icon also appears in the field.
import { FiUser, FiZap, FiUsers, FiBriefcase } from 'react-icons/fi';
const plans = [
{ label: 'Hobby', value: 'hobby', description: 'Free forever, 1 project', icon: <FiUser /> },
{ label: 'Pro', value: 'pro', description: '₹499 / month, unlimited projects', icon: <FiZap /> },
{ label: 'Team', value: 'team', description: '₹1,999 / month, up to 10 seats', icon: <FiUsers /> },
{ label: 'Enterprise', value: 'enterprise', description: 'Contact sales', icon: <FiBriefcase />, disabled: true },
];
<Select label="Plan" defaultValue="pro" options={plans} />Groups#
Nest options one level deep with { label, options: [...] } to render labelled sections. Long lists scroll, and the list opens upwards when there is no room below.
Sizes, error & disabled#
Please choose a plan
<Select size="sm" options={countries} placeholder="Small" />
<Select size="md" options={countries} placeholder="Medium" />
<Select size="lg" options={countries} placeholder="Large" />
<Select label="Plan" error="Please choose a plan" options={plans} />
<Select label="Region" options={regions} defaultValue="bom" disabled />In forms#
Give it a name and the value is submitted with the form through a hidden input. required uses native form validation: try submitting without choosing.
<form onSubmit={(e) => {
e.preventDefault();
console.log(Object.fromEntries(new FormData(e.currentTarget))); // { plan: 'pro' }
}}>
<Select label="Plan" name="plan" required placeholder="Choose a plan" options={plans} />
<Button type="submit">Continue</Button>
</form>NativeSelect#
NativeSelect renders a real <select> with the same field styling. Use it when you want the OS picker on mobile, <optgroup> children, or a form library's register(). Its onChange receives the native event.
<NativeSelect
label="Country"
placeholder="Choose a country"
options={countries}
onChange={(e) => setCountry(e.target.value)}
/>
// React Hook Form
<NativeSelect label="Role" options={roles} {...register('role')} />Used in designs#
Select in real layouts: these 5 designs use it. Open one to try it and copy the code.
- Start ProjectDashboard widgets
- ActivityDashboard widgets
- Invite teammatesAuthentication
- Monthly budgetPricing & billing
- NotificationsSettings & profile
API reference#
<Select />
Forwards its ref to the trigger button. Extra props (aria-*, data-*, onBlur…) go on the trigger.
| Prop | Type | Default | Description |
|---|---|---|---|
options | SelectOption[] | { label, options: SelectOption[] }[] | [] | Options, optionally grouped one level deep. |
children | <option> | <optgroup> elements | - | Native-style alternative to options (merged after them), handy when migrating from <select>. |
value | string | number | null | - | Selected value (controlled). |
defaultValue | string | number | - | Initially selected value (uncontrolled). |
onChange | (value) => void | - | Called with the newly selected value. |
placeholder | ReactNode | 'Select…' | Shown while nothing is selected. |
size | 'sm' | 'md' | 'lg' | 'md' | Field height and font size. |
name | string | - | Submits the value with forms (hidden input). |
emptyText | ReactNode | 'No options' | Shown when options is empty. |
label | ReactNode | - | Label rendered above the control and linked to it via htmlFor. |
helperText | ReactNode | - | Hint shown below the control. |
error | boolean | string | - | Marks the field invalid (red border, aria-invalid). A string also replaces the helper text. |
fullWidth | boolean | false | Makes the field fill its container. |
containerClassName | string | - | Class for the outer wrapper. className goes on the native element. |
required | boolean | false | Native required, plus a red asterisk after the label. |
disabled | boolean | false | Disables and dims the field. |
options[]SelectOption[] | { label, options: SelectOption[] }[]Options, optionally grouped one level deep.
children-<option> | <optgroup> elementsNative-style alternative to options (merged after them), handy when migrating from <select>.
value-string | number | nullSelected value (controlled).
defaultValue-string | numberInitially selected value (uncontrolled).
onChange-(value) => voidCalled with the newly selected value.
placeholder'Select…'ReactNodeShown while nothing is selected.
size'md''sm' | 'md' | 'lg'Field height and font size.
name-stringSubmits the value with forms (hidden input).
emptyText'No options'ReactNodeShown when options is empty.
label-ReactNodeLabel rendered above the control and linked to it via htmlFor.
helperText-ReactNodeHint shown below the control.
error-boolean | stringMarks the field invalid (red border, aria-invalid). A string also replaces the helper text.
fullWidthfalsebooleanMakes the field fill its container.
containerClassName-stringClass for the outer wrapper. className goes on the native element.
requiredfalsebooleanNative required, plus a red asterisk after the label.
disabledfalsebooleanDisables and dims the field.
<SelectOption />
The shape of each option.
| Prop | Type | Default | Description |
|---|---|---|---|
label* | ReactNode | - | Option text (strings also power type-ahead). |
value* | string | number | - | Unique value. |
description | ReactNode | - | Secondary line under the label. |
icon | ReactNode | - | Icon before the label, also shown in the field when selected. |
disabled | boolean | - | Option can't be chosen and is skipped by the keyboard. |
label*-ReactNodeOption text (strings also power type-ahead).
value*-string | numberUnique value.
description-ReactNodeSecondary line under the label.
icon-ReactNodeIcon before the label, also shown in the field when selected.
disabled-booleanOption can't be chosen and is skipped by the keyboard.
<NativeSelect />
Also accepts every native <select> attribute (onChange gets the event) and forwards its ref.
| Prop | Type | Default | Description |
|---|---|---|---|
options | { label: string; value: string | number; disabled?: boolean }[] | - | Shortcut for rendering <option> elements. children also work. |
placeholder | string | - | Disabled first option shown while nothing is selected. |
size | 'sm' | 'md' | 'lg' | 'md' | Field height and font size. |
label | ReactNode | - | Label rendered above the control and linked to it via htmlFor. |
helperText | ReactNode | - | Hint shown below the control. |
error | boolean | string | - | Marks the field invalid (red border, aria-invalid). A string also replaces the helper text. |
fullWidth | boolean | false | Makes the field fill its container. |
containerClassName | string | - | Class for the outer wrapper. className goes on the native element. |
required | boolean | false | Native required, plus a red asterisk after the label. |
disabled | boolean | false | Disables and dims the field. |
options-{ label: string; value: string | number; disabled?: boolean }[]Shortcut for rendering <option> elements. children also work.
placeholder-stringDisabled first option shown while nothing is selected.
size'md''sm' | 'md' | 'lg'Field height and font size.
label-ReactNodeLabel rendered above the control and linked to it via htmlFor.
helperText-ReactNodeHint shown below the control.
error-boolean | stringMarks the field invalid (red border, aria-invalid). A string also replaces the helper text.
fullWidthfalsebooleanMakes the field fill its container.
containerClassName-stringClass for the outer wrapper. className goes on the native element.
requiredfalsebooleanNative required, plus a red asterisk after the label.
disabledfalsebooleanDisables and dims the field.
Accessibility#
- Implements the WAI-ARIA select-only combobox pattern: a button with role="combobox" controlling a role="listbox" via aria-activedescendant. Focus stays on the button.
- Enter, Space, Arrow Up and Arrow Down open the list; arrows, Home and End move; Enter or Space selects; Escape and Tab close.
- Type a few letters to jump to a matching option (type-ahead), with the list open or closed.
- The label, helper text and error are linked to the trigger; required uses native form validation.
- Pressing Escape inside a Modal or Drawer closes only the list, not the dialog.