Select
Styled native select input for predictable keyboard interaction, forms, and simple option lists that benefit from platform behavior.
AccessibleDark Mode3 SizesKeyboard Nav
Install
$
npx react-principles add select01
Theme Preview
Light
expand_more
expand_more
expand_more
Dark
expand_more
expand_more
expand_more
02
Live Demo
Size
expand_more
03
Code Snippet
src/ui/Select.tsx
import { Select } from "@/ui/Select"; <Select label="Framework" options={[ { label: "Next.js", value: "next" }, { label: "Vite", value: "vite" }, { label: "Remix", value: "remix" }, ]} size="md" />
04
Copy-Paste (Single File)
Select.tsx
import { forwardRef, type SelectHTMLAttributes } from "react"; import { cn } from "@/lib/utils"; export type SelectSize = "sm" | "md" | "lg"; export interface SelectOption { label: string; value: string; disabled?: boolean; } export interface SelectProps extends Omit<SelectHTMLAttributes<HTMLSelectElement>, "size"> { label?: string; description?: string; error?: string; size?: SelectSize; options?: SelectOption[]; placeholder?: string; }
05
Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Field label rendered above the select input. |
description | string | — | Helper text shown below the select when no error is present. |
error | string | — | Error text that replaces the description and applies error styles. |
size | "sm" | "md" | "lg" | "md" | Changes the select height, padding, and text size. |
options | SelectOption[] | — | Convenience array for rendering option elements. |
placeholder | string | — | Placeholder option label rendered with an empty value. |
className | string | — | Additional classes merged into the root wrapper. |