Native select
The browser's own select, styled to match the other fields. The platform draws the list: a wheel or sheet on a phone, a plain menu on a desktop. Use it in dense forms and where most visitors are on phones. For a list styled like the rest of the page, with a tick on the selected option, use the select.
Install
npx shadcn@latest add https://thrumui.dev/r/native-select.jsonAdds components/ui/native-select.tsx. Nothing else in your project changes.
import { NativeSelect } from "@/components/ui/native-select";Automatically installs icon chevron-down from the icon set.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
NativeSelect: size | "sm" | "md" | "lg" | Default "md" | sm is 28 pixels tall, md 32, lg 40. It replaces the native size attribute, which would turn the field into a list box. |
NativeSelect: value | string | – | The selected option's value, when the parent holds it. Use it with onChange. |
NativeSelect: defaultValue | string | – | The value selected at first, when the field holds it itself. An empty string selects the placeholder option. |
NativeSelect: onChange | (event: ChangeEvent<HTMLSelectElement>) => void | – | The native change event. The new value is event.target.value. |
NativeSelect: disabled | boolean | Default false | The native attribute: the field is dimmed and cannot be opened. |
NativeSelect: aria-invalid | boolean | – | Marks the value as wrong: the border takes the destructive colour. Pair it with a message linked by aria-describedby. |
NativeSelect: sound | boolean | Default true | Play a soft click when an option is chosen, if the visitor has sound on. |
NativeSelect: className | string | – | Extra classes for the wrapper that holds the field and its chevron, merged last. The field fills its container; set a width here. |
NativeSelect: ...props | ComponentProps<"select"> | – | Every other select attribute and event handler goes to the select element: id, name, required, autoComplete. |
NativeSelectOption: value | string | – | What the field reports and submits. An option with an empty value works as the placeholder: while it is selected the field's text is muted. |
NativeSelectOption: disabled | boolean | Default false | Shown in the list, but it cannot be picked. On the placeholder option it stops a visitor going back to no answer. |
NativeSelectOptGroup: label | string | – | The heading the platform shows above the group's options. |
Motion and sound
Motion
- The border colour changes over 150 ms when the field becomes invalid or valid again.
- The list opens and closes the way the platform does it.
- Reduced motion: the border changes at once.
Sound
- A soft click when another option is chosen.
Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works
Accessibility
- It is a native select element, so its role, its keyboard and the list a screen reader hears come from the browser.
- Its name comes from a label element linked with htmlFor and id. The placeholder option is not a name.
- The focus ring is 2 pixels of the theme's ring colour, drawn over the border.
- An invalid field is marked with aria-invalid and its border changes colour. The message next to it carries the meaning.
- Text is 16 pixels on phones, so the page does not zoom when the field takes focus, and 14 pixels on wider screens.
- A long option is cut with an ellipsis in the field and shown in full in the list. Nothing overflows at 160 pixels wide.
- The chevron sits at the end of the field, so it moves to the left in a right-to-left layout.
| Keys | Action |
|---|---|
| Tab | Focus the field. |
| Space / Enter / Alt + ↓ | Open the platform's list. |
| ↓ / ↑ | Pick the next or previous option. On Windows and Linux this works on the closed field too. |
| A to Z | Pick the next option that starts with the typed letters. |
| Esc | Close the list and keep the value. |
Source
"use client";
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";
import { ChevronDownIcon } from "@/components/icons/chevron-down";
import { play } from "@/lib/thrum-sound";
export type NativeSelectSize = "sm" | "md" | "lg";
export type NativeSelectProps = Omit<ComponentProps<"select">, "size"> & {
/** `sm` is 28 pixels tall, `md` 32, `lg` 40. It replaces the native `size` attribute, which turns a select into a list box. */
size?: NativeSelectSize;
/** Play a soft click when an option is chosen, if the visitor has sound on. */
sound?: boolean;
};
const SIZE: Record<NativeSelectSize, string> = {
sm: "h-7 ps-2 pe-7",
md: "h-8 ps-2.5 pe-8",
lg: "h-10 ps-3 pe-9",
};
/**
* A native `<select>` with the theme's border, focus ring and chevron. The list is the platform's own picker, which is
* the better one on a phone and in dense forms. Give it a `<label>`. For groups with a styled list, use the select.
*/
export function NativeSelect({ size = "md", sound = true, className, onChange, children, ...props }: NativeSelectProps) {
return (
<div data-slot="native-select-wrapper" className={cn("relative w-full min-w-0 has-[>select:disabled]:opacity-50", className)}>
<select
data-slot="native-select"
data-surface="control"
className={cn(
// 16px text on phones: anything smaller makes iOS zoom the page when the field takes focus.
"w-full min-w-0 cursor-pointer appearance-none truncate rounded-md border border-input bg-background text-base text-foreground md:text-sm",
"transition-[border-color] duration-150 ease-out motion-reduce:transition-none",
"focus-visible:outline-2 focus-visible:-outline-offset-1 focus-visible:outline-ring",
"disabled:cursor-not-allowed aria-invalid:border-destructive",
// While the empty option is the selected one, its text reads as a placeholder.
"has-[option[value='']:checked]:text-muted-foreground",
SIZE[size],
)}
onChange={(event) => {
if (sound) play("select");
onChange?.(event);
}}
{...props}
>
{children}
</select>
<ChevronDownIcon
size={16}
className={cn("pointer-events-none absolute top-1/2 -translate-y-1/2 text-muted-foreground", size === "lg" ? "end-3" : size === "sm" ? "end-2" : "end-2.5")}
/>
</div>
);
}
/** One option. The platform draws the open list, so only its colours follow the theme. */
export function NativeSelectOption({ className, ...props }: ComponentProps<"option">) {
return <option data-slot="native-select-option" className={cn("bg-background text-foreground", className)} {...props} />;
}
/** Options that belong together, under the group's `label`. */
export function NativeSelectOptGroup({ className, ...props }: ComponentProps<"optgroup">) {
return <optgroup data-slot="native-select-optgroup" className={cn("bg-background text-foreground", className)} {...props} />;
}Files and dependencies
- Adds
components/ui/native-select.tsx- Packages
- None
- Brings along
- Sound engine
- Icons
chevron-down
Changelog
- 1.0.0 · 2026-12-03First release.