Native select
A styled native <select> with a Keyline chevron.
The browser's own menu: reach for it on phones and in dense forms. Use @khaeli/select when the list needs groups with separators, or to open in the system's style.
With a label
import { Label } from "@/components/ui/label"
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
export default function NativeSelectWithALabel() {
return (
<div className="grid gap-2">
<Label htmlFor="native-select-status">Status</Label>
<NativeSelect id="native-select-status" defaultValue="in-progress">
<NativeSelectOption value="backlog">Backlog</NativeSelectOption>
<NativeSelectOption value="in-progress">In progress</NativeSelectOption>
<NativeSelectOption value="in-review">In review</NativeSelectOption>
<NativeSelectOption value="done">Done</NativeSelectOption>
</NativeSelect>
</div>
)
}
Sizes
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
export default function NativeSelectSizes() {
return (
<div className="flex flex-wrap items-center gap-2">
<NativeSelect size="sm" aria-label="Rows per page, small" defaultValue="25">
<NativeSelectOption value="10">10 rows</NativeSelectOption>
<NativeSelectOption value="25">25 rows</NativeSelectOption>
<NativeSelectOption value="50">50 rows</NativeSelectOption>
</NativeSelect>
<NativeSelect aria-label="Rows per page, default" defaultValue="25">
<NativeSelectOption value="10">10 rows</NativeSelectOption>
<NativeSelectOption value="25">25 rows</NativeSelectOption>
<NativeSelectOption value="50">50 rows</NativeSelectOption>
</NativeSelect>
</div>
)
}
With groups
import { Label } from "@/components/ui/label"
import { NativeSelect, NativeSelectOptGroup, NativeSelectOption } from "@/components/ui/native-select"
export default function NativeSelectWithGroups() {
return (
<div className="grid gap-2">
<Label htmlFor="native-select-release">Release</Label>
<NativeSelect id="native-select-release" defaultValue="4.2">
<NativeSelectOptGroup label="Upcoming">
<NativeSelectOption value="4.3">4.3, in planning</NativeSelectOption>
<NativeSelectOption value="4.2">4.2, in testing</NativeSelectOption>
</NativeSelectOptGroup>
<NativeSelectOptGroup label="Shipped">
<NativeSelectOption value="4.1">4.1</NativeSelectOption>
<NativeSelectOption value="4.0">4.0</NativeSelectOption>
</NativeSelectOptGroup>
</NativeSelect>
</div>
)
}
Disabled
import { Label } from "@/components/ui/label"
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
export default function NativeSelectDisabled() {
return (
<div className="group grid gap-2" data-disabled="true">
<Label htmlFor="native-select-currency">Currency</Label>
<NativeSelect id="native-select-currency" defaultValue="usd" disabled>
<NativeSelectOption value="usd">US dollar</NativeSelectOption>
<NativeSelectOption value="eur">Euro</NativeSelectOption>
</NativeSelect>
</div>
)
}
Invalid
Choose the team that owns this project.
import { Field, FieldError, FieldLabel } from "@/components/ui/field"
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"
export default function NativeSelectInvalid() {
return (
<Field data-invalid="true" className="w-56">
<FieldLabel htmlFor="native-select-owner">Owner</FieldLabel>
<NativeSelect
id="native-select-owner"
defaultValue=""
required
aria-invalid
aria-describedby="native-select-owner-error"
>
<NativeSelectOption value="" disabled>
Choose a team
</NativeSelectOption>
<NativeSelectOption value="design">Design</NativeSelectOption>
<NativeSelectOption value="engineering">Engineering</NativeSelectOption>
<NativeSelectOption value="finance">Finance</NativeSelectOption>
</NativeSelect>
<FieldError id="native-select-owner-error">Choose the team that owns this project.</FieldError>
</Field>
)
}
Installation
npx shadcn@latest add @khaeli/native-selectbunx --bun shadcn@latest add @khaeli/native-selectInstall @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.
Installs with
- Registry items
- npm packages
- @keyline-icons/react ^2.2.0
Keyboard
Tab- Moves focus to the select. A
disabledselect leaves the tab order. A to Z- Picks the next option that starts with the letter, without opening the menu.
SpaceArrowDownArrowUp- Open the menu or step through the options: the menu and its keys are the operating system's, not the item's.
Accessible name
- The
idgoes to the<select>, so a @khaeli/label withhtmlFornames it. Without a visible label, usearia-label. classNamegoes to the wrapper that holds the chevron; every other prop goes to the<select>.- An invalid control carries
aria-invalidand lists theidof its message inaria-describedby, so the message is read as its description. @khaeli/field lays the label, control and message out.
Registry JSON
The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/native-select.json