Skip to content
Esc
↑↓navigate↵open⌘Jpreview
On this page

Native Select for Astro

Styled native HTML select controls for Astro forms.

Installation

bunx --bun shadcn@latest add @gnostic/native-select

Usage

import {
    NativeSelect,
    NativeSelectOptGroup,
    NativeSelectOption,
} from "@/components/ui/native-select"
<NativeSelect>
  <NativeSelectOption value="">Select a fruit</NativeSelectOption>
  <NativeSelectOption value="apple">Apple</NativeSelectOption>
  <NativeSelectOption value="banana">Banana</NativeSelectOption>
  <NativeSelectOption value="blueberry">Blueberry</NativeSelectOption>
  <NativeSelectOption value="grapes" disabled> Grapes </NativeSelectOption>
  <NativeSelectOption value="pineapple">Pineapple</NativeSelectOption>
</NativeSelect>

Composition

Use options directly under NativeSelect for a simple list:

NativeSelect
├── NativeSelectOption
├── NativeSelectOption
├── NativeSelectOption
└── NativeSelectOption

Use NativeSelectOptGroup to organize options into categories:

NativeSelect
├── NativeSelectOptGroup
│   ├── NativeSelectOption
│   └── NativeSelectOption
└── NativeSelectOptGroup
    ├── NativeSelectOption
    └── NativeSelectOption

Examples

With Groups

Organize options using NativeSelectOptGroup for better categorization.

Disabled State

Disable individual options or the entire select component.

Invalid State

Show validation errors with the aria-invalid attribute and error styling.

Accessibility

  • The component maintains all native HTML select accessibility features.
  • Screen readers can navigate through options using arrow keys.
  • The chevron icon is marked as aria-hidden="true" to avoid duplication.
  • Use aria-label or aria-labelledby for additional context when needed.
<NativeSelect aria-label="Choose your preferred language">
  <NativeSelectOption value="en">English</NativeSelectOption>
  <NativeSelectOption value="es">Spanish</NativeSelectOption>
  <NativeSelectOption value="fr">French</NativeSelectOption>
</NativeSelect>

API Reference

Read the installed source for the complete prop types.

When to use Native Select

Use NativeSelect when a standard browser selection control fits the task. Put native option and optgroup elements inside it, then set name, ID, and a linked label.

Keyboard and behavior

The browser owns keyboard navigation, touch pickers, form submission, and disabled behavior. These details can differ across platforms. Keep option labels clear without depending on custom icons or markup.

Theme and layout

The size prop changes the component’s visual size. Native option popup colors and spacing are not fully controlled by the page theme. Test the closed control and the open picker on target platforms.