Native Select

The Native Select component lets users choose an option from a dropdown list using the browser’s built-in select menu. It provides a simple and familiar way to handle selections.

It uses the native HTML select behavior, which works well on mobile devices and supports accessibility by default.

Built with React and styled using Tailwind CSS and the Tailgrids theme tokens. It supports two sizes, error and success states, placeholders and grouped items.

Installation

Install the component using the Tailgrids CLI.

npx @tailgrids/cli@latest add native-select

Anatomy

Import the component and pass the required props.

import {
  NativeSelect,
  NativeSelectOption
} from "@/components/tailgrids/native-select";

export const NativeSelectExample = () => (
  <NativeSelect>
    <NativeSelectOption value="option1">Option 1</NativeSelectOption>
    <NativeSelectOption value="option2">Option 2</NativeSelectOption>
  </NativeSelect>
);

Examples

States

Mark the select invalid with isInvalid (or aria-invalid) for the error state, and use state="success" for the success state. isInvalid is also read from a surrounding Field.

Success message

Error message

Placeholder

Use the placeholder prop to display a placeholder when no value is selected.

Disabled

The component can be disabled to prevent user interaction.

Option Groups

Use NativeSelectOptGroup to group related options together.

API Reference

NativeSelect

Extends the native select element props.

PropTypeDefaultDescription
size'sm' | 'default''default'The size of the select
isInvalidbooleanfalseShows the error state (same as aria-invalid)
state'default' | 'success''default'Shows the success state
placeholderstring-Sets a placeholder for the select
disabledboolean-Disables the select
classNamestring-Additional CSS classes to apply to the select element

NativeSelectOption

PropTypeDefaultDescription
classNamestring-Additional CSS classes

NativeSelectOptGroup

PropTypeDefaultDescription
classNamestring-Additional CSS classes

Accessibility

  • Semantic structure: Uses the native <select> element, so it follows standard form behavior by default.
  • Keyboard support: Users can open the dropdown and move between options using keyboard keys such as Arrow keys, Enter, and Space.
  • Label association: The select can be linked to a label using htmlFor and id, so users understand what the field is for.
  • Screen reader support: Options, selected values, and groups are handled through the browser’s built-in accessibility behavior.
  • Disabled state: Disabled selects and options are handled natively and are not interactive.