Skip to content

Components / Native Select

Native Select

A square, monospaced native select. Choose from labeled options with native keyboard, form and validation behavior. The browser owns the option popup; OS styling varies.

Storybook runs locally or as a separately hosted build; no hosted Storybook is configured. Source and setup links match the install revision.

Usage playground

Choose a status in a controlled native select. Preview disabled or explicit invalid presentation; your application owns the value and validation.

React / TSX
'use client';

import { useId, useState } from 'react';
import { NativeSelect } from "@/components/ui/yads-native-select";
import { Label } from "@/components/ui/yads-label";

Installation

pnpm dlx [email protected] add biehlio/yet-another-design-system/native-select#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

Documentation samples use basic Tailwind utilities for layout. Install each YADS component imported by the sample.

Run this revision-pinned command in a project configured for shadcn. It installs yads-native-select, its scoped stylesheet and JetBrains Mono. Import { NativeSelect } from @/components/ui/yads-native-select (adjust the alias to your project). No global CSS, Tailwind utilities, theme install or form library is required.

Copy sample includes the complete consumer module and any recipe CSS, even when collapsed. Interactive examples include a client boundary for React Server Component apps. These examples compose the separately installed YADS Label and, for form actions, Button. Native Select itself does not depend on other primitives. Install the sample companions explicitly at the same revision:

pnpm dlx [email protected] add biehlio/yet-another-design-system/label#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40 biehlio/yet-another-design-system/button#e7b31d0e0c9d8b24d53e97ca38b3b68d345e9f40

Groups and disabled options

Compose native option and optgroup elements. Disable the whole select, individual options or groups; explain unavailable choices nearby. The browser owns the popup and may style it differently on each OS.

Security and Operations are not accepting requests.

React / TSX
'use client';

import { useId } from 'react';
import { NativeSelect } from "@/components/ui/yads-native-select";
import { Label } from "@/components/ui/yads-label";

Helper text and errors

Connect helper and error IDs with aria-describedby. This example starts invalid and checks native required validity on change; the application decides when to show feedback. aria-invalid alone does not block submission.

Choose the access needed for this project.

Choose a role.

React / TSX
'use client';

import { useId, useState } from 'react';
import { NativeSelect } from "@/components/ui/yads-native-select";
import { Label } from "@/components/ui/yads-label";

Native form submission

An uncontrolled defaultValue, required validation, name/FormData and browser reset. This local demo reports a result without sending a request. The empty first option is a native required placeholder, not a custom placeholder API.

React / TSX
'use client';

import { useId, useState } from 'react';
import { NativeSelect } from "@/components/ui/yads-native-select";
import { Label } from "@/components/ui/yads-label";
import { Button } from '@/components/ui/yads-button';

Native size and multiple

size remains the native numeric row count, not a custom visual variant. multiple uses an array defaultValue and repeated FormData entries (getAll). Listboxes omit the decorative dropdown chevron.

Choose one or more. Use your platform’s modifier keys to select several options; touch selection varies by browser.

React / TSX
'use client';

import { useId, useState } from 'react';
import { NativeSelect } from "@/components/ui/yads-native-select";
import { Label } from "@/components/ui/yads-label";
import { Button } from '@/components/ui/yads-button';

className customization

Add ordinary CSS with sufficient specificity. This border recipe preserves scoped light/dark colors, invalid styling and keyboard focus. className and style reach the select itself. The copied module includes the recipe CSS.

React / TSX
'use client';

import { useId } from 'react';
import { NativeSelect } from "@/components/ui/yads-native-select";
import { Label } from "@/components/ui/yads-label";

Accessibility

  • Give every select a visible name. Use a native label with htmlFor matching a unique select id. React useId supports repeated instances. Option text or a placeholder option is not a label.
  • Connect requirements and feedback. Mark required fields visibly and with required. Use aria-describedby to connect helper/error text and aria-invalid="true" when showing an error. Include actionable text, not color alone. The application owns validation timing and feedback.
  • Keep native keyboard behavior. Tab reaches enabled selects; arrows and type-ahead navigate options according to the browser and OS. Popup opening and multiple-selection gestures vary by platform. Disabled selects leave the tab order and FormData; disabled options/groups cannot be chosen. Explain unavailability nearby.
  • Keep the browser in charge. Do not replace native roles, intercept navigation keys or add interactive content inside options. The SVG background chevron is decorative, absent from the accessibility tree and cannot intercept clicks. It is omitted for listboxes; forced-colors uses the browser arrow.

Light is standalone by default. A containing className="dark" enables scoped dark colors without global CSS or a theme provider. The option popup remains browser-owned; YADS does not promise pixel-identical OS styling.

API reference

Import { NativeSelect, type NativeSelectProps } from @/components/ui/yads-native-select. NativeSelectProps is React.SelectHTMLAttributes<HTMLSelectElement>. It renders one native select with no custom variants, value management or form-library dependency. Use native option and optgroup children.

On narrow screens, focus the table and scroll horizontally to read all columns.

NativeSelect props, types, defaults and behavior
PropTypeDefaultDescription
childrenReactNodeNot setCompose native option and optgroup elements. Provide option values and group labels; no custom popup or wrappers are required.
id / namestringNot setAssociate a visible label with id/htmlFor. name includes enabled selected values in FormData. No IDs or labels are generated.
value / onChangeNative value / ChangeEventHandler<HTMLSelectElement>Not setControlled: update value synchronously on change. Use an array for multiple; read selectedOptions for all selected values. Do not switch controlled/uncontrolled.
defaultValuestring | number | readonly string[]Not setInitial uncontrolled selection. Native reset restores it; do not combine with value or set selected on options. Without a value the browser selects the first available option in a single-select.
disabledbooleanfalseNative: unavailable, skipped by Tab and excluded from submission. Options and optgroups may also be disabled independently.
requiredbooleanfalseNative constraint validation; no messages or aria-invalid are generated. For a single-select placeholder use an empty first option directly inside the select.
sizenumberNot set (browser default)Native visible row count, not a visual variant. Values greater than 1 show a listbox without the decorative chevron.
multiplebooleanfalseAllows several selections using platform-specific interactions. No chevron. Use FormData.getAll(name) for repeated values.
formstringNot setAssociates the select with a form by its id, including when outside that form. Submission and reset remain native.
aria-invalid / aria-describedbyNative ARIA valuesNot settrue styles an invalid select. Connect external helper/error IDs; aria-invalid itself does not block submission.
className / stylestring / CSSPropertiesNot setApplied to the select, retaining its scoped class. No wrapper receives consumer props.
refReact.Ref<HTMLSelectElement>Not setForwarded to the actual select for focus, selectedOptions and native validity methods.

Native attributes and events

Native autoComplete, onChange, onFocus, onBlur, onInvalid, aria-*, data-* and other select attributes pass through unchanged. No value, ID, name, required state or label is supplied automatically. For a value that cannot be changed, present text or explain a disabled control, accounting for its exclusion from submission.

Playground defaults

Reset restores enabled, controlled status “To do” (value todo). The state menu is a documentation control, not a component prop. The invalid preview demonstrates presentation rather than a validation algorithm.