Native select
The browser's own select, in the Select trigger's look. The system draws the list that opens. Four sizes, two variants, options of text only.
<NativeSelect aria-label="Region" defaultValue="eu-west-1"> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption></NativeSelect><NativeSelect variant="ghost" aria-label="Time range" defaultValue="24h"> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect>Installation
import { NativeSelect, NativeSelectOptGroup, NativeSelectOption } from "@catalog-developer/components";Usage
<NativeSelect aria-label="Region" defaultValue="us-east-1">
<NativeSelectOption value="us-east-1">US East</NativeSelectOption>
<NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption>
</NativeSelect>Use the native select when the system's own menu is what you want and every option is text only. For a menu with its own design, such as an option with an icon, use the Select. No rule of ours says where in the dashboard a native select goes, or when a short list is a select and when it is a radio group: both are open questions below.
Anatomy
- 1 — The select. A real
<select>with the browser's look taken off: the Select trigger's fill, its edge (a shadow, never a border) and the button's corners. A div around it places the chevron. - 2 — Value. The chosen option's text, on one line, medium weight. Past the control's width it is cut with an ellipsis.
- 3 — Chevron.
ChevronDownSmall, the small chevron, in the quiet icon color. It is drawn over the select, takes no clicks and is hidden from assistive technology. - The list. Not in the picture: the options and their groups, which the system draws when the select opens. On a Mac it is the macOS menu.
| Size | Height | Text | Left inset | Chevron | Chevron to the edge | Corners |
|---|---|---|---|---|---|---|
md | 32px | label-2, 13px | 12px | 14px | 10px | 8px |
sm | 28px | label-2, 13px | 10px | 14px | 8px | 8px |
xs | 24px | label-3, 12px | 8px | 12px | 6px | 6px |
xxs | 20px | label-4, 11px | 6px | 10px | 4px | 5px |
The dashboard's rule is the small chevron at 14px. The component draws it at 14px at md and sm, and at 12 and 10px at xs and xxs, as the Select's trigger does. The colors come from ds/tokens/native-select.css, where each slot points at the Select trigger's token or the ghost button's, so they change together, in light and in dark.
In the dashboard
Not in the dashboard yet: no screen there uses it, and none writes a <select>. Apart from its own page, its users are two places in the catalog. Each card is a copy of the real use and names its file.
A playground knob
SelectControl, the catalog's pick-one-of-many knob: xxs, hugging, capped at 144px wide.
catalog/app/_components/page-kit.tsx
Rows, in the Card playground
Its table footer's pager: the word Rows, then the select at sm, named "Rows per page" for a screen reader.
catalog/app/components/card/card-playground.tsx
Sizes
The button's four: md is 32px tall (the default), sm 28px, xs 24px and xxs 20px. The text is 13px at md and sm, 12px at xs, 11px at xxs. A card's header, footer and toolbar take controls of 28px at most, so sm or smaller there.
<NativeSelect size="md" aria-label="Time range" defaultValue="24h"> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect><NativeSelect size="sm" aria-label="Time range" defaultValue="24h"> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect><NativeSelect size="xs" aria-label="Time range" defaultValue="24h"> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect><NativeSelect size="xxs" aria-label="Time range" defaultValue="24h"> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect>Variants
default is the Select's trigger, which is the secondary button's look: its fill, its edge, its text. ghost is the ghost button's: no edge, and no fill until the pointer is over it. Both keep the chevron.
<NativeSelect variant="default" aria-label="Time range" defaultValue="24h"> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect><NativeSelect variant="ghost" aria-label="Time range" defaultValue="24h"> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect>Width
hug, the default, is as wide as the chosen value, so the control changes width when the value does. fixed takes the width of its container and cuts a longer value with an ellipsis. A hugging select grows past its container (measured in Chromium): give it a max width with className, as the third one has, and the value is cut there.
<div className="flex w-56 flex-col items-start gap-3"> <NativeSelect width="hug" aria-label="Region" defaultValue="us-east-1"> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption> </NativeSelect> <NativeSelect width="fixed" aria-label="Region" defaultValue="us-east-1"> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption> </NativeSelect> <NativeSelect width="hug" className="max-w-40" aria-label="Gateway" defaultValue="eu"> <NativeSelectOption value="eu">eu-central-1 production, primary gateway</NativeSelectOption> <NativeSelectOption value="us">us-east-1 staging</NativeSelectOption> </NativeSelect></div>Value
defaultValue names the option chosen at first, and the browser holds the value from then on. Without it, the first option is chosen. value with onChange, as in the second one: the screen holds the value. onChange is the native change event, so the new value is e.target.value, always a string.
<NativeSelect aria-label="Region" defaultValue="eu-west-1"> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption></NativeSelect> const [range, setRange] = useState("24h"); <NativeSelect aria-label="Time range" value={range} onChange={(e) => setRange(e.target.value)}> <NativeSelectOption value="1h">Last hour</NativeSelectOption> <NativeSelectOption value="24h">Last 24 hours</NativeSelectOption> <NativeSelectOption value="7d">Last 7 days</NativeSelectOption></NativeSelect><span className="text-body-2 text-neutral-fg-secondary">Showing {range}</span>Placeholder option
There is no placeholder prop. A placeholder is a first option with an empty value that says what to choose, as in the Invalid example below. Add disabled and hidden to it, as here, and it leaves the list: once something is picked, nobody can go back to nothing. Polaris and Primer both say to start on a default option when one fits, and Polaris keeps the prompt for when none does.
<NativeSelect aria-label="Region" defaultValue=""> <NativeSelectOption value="" disabled hidden>Select a region</NativeSelectOption> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption></NativeSelect>Option groups
NativeSelectOptGroup puts options under a label. The system draws the label, and it can't be chosen. disabled on an option, or on a whole group, keeps it in the list and stops it being chosen. Open the select to see it: Europe Central, and all of Asia Pacific.
<NativeSelect aria-label="Region" defaultValue="eu-west-1"> <NativeSelectOptGroup label="Europe"> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1" disabled>Europe Central</NativeSelectOption> </NativeSelectOptGroup> <NativeSelectOptGroup label="Asia Pacific" disabled> <NativeSelectOption value="ap-south-1">Asia South</NativeSelectOption> </NativeSelectOptGroup></NativeSelect>Disabled
On the select, disabled is the native attribute: no focus, no list, and its value is left out of a submitted form. The whole control dims to half, chevron included. On an option or a group, see Option groups above.
<NativeSelect disabled aria-label="Region" defaultValue="us-east-1"> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption></NativeSelect>Invalid
aria-invalid marks the select as wrong: a soft red ring, 2px wide, and assistive technology is told the value is invalid. It draws no message. The words go under it, in a Field's error, as in the next example.
<NativeSelect aria-invalid aria-label="Region" defaultValue=""> <NativeSelectOption value="">Select a region</NativeSelectOption> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption></NativeSelect>In a field and a form
A Field gives it a title, a description and an error. A native select is not a Base UI control, so the Field can't find it: give the select an id and the Field the same htmlFor. The title is then a real <label>, and a press on it focuses the select. With htmlFor the Field is plain markup, so set aria-invalid yourself beside its error. name submits the value with the form, and required uses the browser's own check: a first option with an empty value counts as nothing chosen. Press Save without picking a region to see the browser's message.
<form className="flex w-64 flex-col gap-4" onSubmit={(e) => e.preventDefault()}> <Field title="Region" description="Where the gateway runs." error="Select a region." htmlFor="docs-region"> <NativeSelect id="docs-region" name="region" required width="fixed" aria-invalid defaultValue=""> <NativeSelectOption value="">Select a region</NativeSelectOption> <NativeSelectOption value="us-east-1">US East</NativeSelectOption> <NativeSelectOption value="us-west-2">US West</NativeSelectOption> <NativeSelectOption value="eu-west-1">Europe West</NativeSelectOption> <NativeSelectOption value="eu-central-1">Europe Central</NativeSelectOption> </NativeSelect> </Field> <Button type="submit" color="primary" emphasis="high" className="self-start">Save</Button></form>API Reference
NativeSelect
A <div> around a <select> and its chevron. className goes on the div. Every other prop goes to the <select>: the ones below and every other attribute of the element (id, form, aria-describedby, ref…). HTML's own size (how many rows show) is replaced by ours. multiple is not taken out of the type, but it turns a select into a list box, which this one-line control is not drawn for.
| Prop | Type | Default | Description |
|---|---|---|---|
size | "md" | "sm" | "xs" | "xxs" | "md" | 32, 28, 24 or 20px tall: the button's sizes, with its padding, text, corners and icon size. Not HTML's size. |
variant | "default" | "ghost" | "default" | The Select's trigger (the secondary button's look), or the ghost button's: no edge, no fill until hover. |
width | "hug" | "fixed" | "hug" | As wide as its value, or as wide as its container. |
value | string | number | readonly string[] | — | The chosen option's value, held by the screen. Needs onChange. |
defaultValue | string | number | readonly string[] | — | The option chosen at first, when the browser holds the value. Without it, the first option. |
onChange | ChangeEventHandler<HTMLSelectElement> | — | The native change event. The new value is e.target.value. |
disabled | boolean | false | No focus, no list, not submitted. The control dims to half. |
aria-invalid | boolean | "true" | "false" | "grammar" | "spelling" | — | True draws the red ring and marks the value as invalid for assistive technology. |
aria-label | string | — | Its name, where no visible label names it. A select with neither has no name at all. |
name | string | — | The key its value is submitted under in a form. |
required | boolean | false | The browser refuses to submit while the chosen option is a first option with an empty value. |
className | string | — | On the wrapper, not the select: where the control sits (a margin, a max width). Never its look. |
onPointerDown, onKeyDown, onBlur | event handlers | — | Yours run after the control's own, which hide the focus ring after a mouse pick and show it again on a key. |
children | ReactNode | — | NativeSelectOption and NativeSelectOptGroup. |
NativeSelectOption
An option element, with every prop of one.
| Prop | Type | Default | Description |
|---|---|---|---|
value | string | number | readonly string[] | — | What the select's value becomes. Left out, the option's text. Empty on a first option, it is the placeholder. |
disabled | boolean | false | Stays in the list and can't be chosen. |
hidden | boolean | false | Leaves the list. With disabled, for a placeholder nobody can go back to. |
children | ReactNode | — | The label. Text only: the system draws it. |
NativeSelectOptGroup
An optgroup element, with every prop of one.
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | The group's heading in the list: text only, drawn by the system, never chosen. |
disabled | boolean | false | Disables every option in the group. |
children | ReactNode | — | Its NativeSelectOptions. HTML does not let a group hold a group. |
Rules
Native select or Select
The system's menu, or ours
The native select opens the system's own menu, and its options are text only. When the menu needs a design of its own, use the Select. If an option needs an icon, or the list needs our look, it is not a native select.
That is all the component decides. Where a native select goes in the dashboard is an open question below.
Options
Short, in an order people can guess, grouped sparingly
Keep each option to one line of plain words, in sentence case. Put the options in the order that makes most sense for the list: numbers from small to large.
Group when people already know the categories, such as continents for regions, or when a name repeats across them. Group every option or none, and never make a group of one.
From Atlassian (one line for each option, in common words; the order that makes most sense, such as most chosen first or by number; no A to Z, which does not suit translation; groups used sparingly), Primer (a logical order, A to Z by default; no emoji before an option's text, which breaks typing to jump) and Polaris (A to Z or another logical order; sentence case). They differ on A to Z, and ours is not decided.
Label
Named, and not by its placeholder
In a form, give the select a visible label: a Field's title, tied to it with htmlFor and id, as in the example above. The placeholder says what to do ("Select a region") and the label says what it is ("Region").
Where the text beside it already names it, it may go without a visible label. It then takes an aria-label.
From Primer (a label that stays visible; a placeholder never stands in for it; hide the label only where visible text beside the select already names it) and Atlassian (the label outside the field, where it stays in view).
Look
It looks like the Select's trigger
The default native select is the Select's trigger, which is the secondary button's look: the same fill, edge, text and hover, from the same tokens.
Never write a bare <select> in a screen, and never restyle this one with classes: screens are built from the shared components, and an edge is a shadow, never a border. className is for where it sits. Its look is size, variant and width.
Open questions
Where does a native select go?
OpenNot decided. The component says only this: the system's menu and text-only options are the native select, a designed menu is the Select. The table rule says a pagination always shows the rows per page, not which select draws it. The ds Pagination draws the Select there, at xs. The catalog's Card playground draws a native select, at sm. The two disagree.
shadcn keeps both and picks the native one for the browser's own behavior, for speed and for phones, and its Select for a styled list, motion and richer interaction. Primer's Select is the native element, so it follows the person's system and browser.
A few options: a select or a radio group?
OpenNot decided. No rule of ours gives a number of options.
Polaris: a select from four options up, and its choice list for fewer. Primer: for six or fewer, think of a radio group when there is room. Atlassian gives no number: radio buttons to pick one of a set.
Focus and invalid: the Select's, or its own?
OpenThe Select's trigger takes the Input's focus and invalid shadows. The native select draws a 2px ring of its own for each. Side by side, the two selects differ as soon as one is focused or wrong.
shadcn gives its native select the same focus and invalid classes as its Input (read in its source).
Should a placeholder look like one?
OpenThe Select draws its placeholder in the muted text. The native select draws a first, empty option in the full text color, so "Select a region" reads as a value.
Polaris and Primer take the placeholder as a prop. Primer hides it from the list when the select is required. shadcn leaves it to an option, as we do.
Should the Field find a native select?
OpenA Field names, describes and marks invalid an Input, a Textarea or a Select by itself. A native select needs htmlFor and its own aria-invalid, and the Field's description and error then have no id to point aria-describedby at. The Field's card row pads 16px around a control it knows, and its list does not name the native select, so that row keeps the 12px of a row of text. Its title centering does not know it either.
Polaris builds the label, the help text and the error into its select. Primer's examples wrap it in a form control with a label, a caption and a validation message. shadcn marks its Field with data-invalid and the select with aria-invalid.
Accessibility
It is the browser's own select. The component adds a look, a chevron and one focus fix, and sets no role and no tab order (source).
Its name. A select needs one. In a form it is a <label>: a Field with htmlFor and the select's id, and a press on that label focuses the select (checked in Chromium). Elsewhere it is aria-label. A Field does not find a native select by itself, as it finds an Input or a Select, so without htmlFor its title names nothing (source). The Field's error is then a role="alert", announced when it appears, and is not tied to the select.
Its role. Chromium exposes it as a combobox with its name and its options (checked in the page's accessibility tree). MDN gives the same role for a select with no multiple and no size above 1. disabled and aria-invalid are the element's own attributes. The chevron is aria-hidden (source). How each screen reader words all this was not tested.
Focus. A keyboard focus draws a 2px ring (checked in Chromium). After a mouse pick the browser leaves the select focused and would keep the ring on, so the component hides it until a key is pressed or the focus leaves (source).
Keyboard. Tab reaches it unless it is disabled. The keys that open it and move through it are the system's, and typing an option's first letters moves to it: the component's source names that for the macOS menu.
From knowledge only, not tested here. On a Mac, Space or an arrow key opens the menu. On Windows, the arrow keys change the value in place and Alt with the down arrow opens the list. A phone or a tablet opens its own picker, with rows sized for a finger whatever the size of our control.
What others expose
What the same control takes in shadcn/ui, Shopify Polaris, GitHub Primer and Atlassian's design system that ours does not, each read on that system's own page or in its source. Polaris's and Primer's Select are the native element. shadcn has a native select and a Select, as we do. Atlassian's page does not say which its select is.
| They expose | Who | Ours |
|---|---|---|
| A label, help text and an error message built in | Polaris (label, helpText, error); Primer through its form control | The Field's title, description and error. See the open question on how the Field finds this control. |
A placeholder prop | Polaris, Primer | No prop: a first option with an empty value does it, as in shadcn. |
Options as data (an options array) | Polaris | The options are children, as in HTML and in shadcn. A list is one map. |
An element before the chosen value (prefix on an option, shown in the control and not in the list) | Polaris | None: an option is text only. A value with an icon is the Select. |
| A required mark | Polaris (requiredIndicator); Primer's anatomy has one | The Field's badge for Required, and optional for the reverse. |
A success state (validationStatus) | Primer | None: its one validation state is aria-invalid. |
A full-width switch (block) | Primer | width="fixed". |
| Three sizes: small, medium, large (their heights were not verified) | Primer | Four, from 32px down to 20px. |
A higher-contrast fill (contrast) | Primer | One fill for each variant, from tokens. |
| Several values, a clear control, creating an option | Atlassian | None: this control picks one value from the system's list. |
| Right-to-left layout | shadcn | None: the chevron is placed from the right edge. |