Skip to content
All components
Forms

Native select

Choose one value with the platform's own select element, styled to match the other fields.

The platform picker, styled. Better than a rebuilt one on a phone.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add native-select

Then import it from @/components/ui/native-select. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

With label

Choose a value with the platform picker and a visible associated label. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Label } from "@/components/ui/label"
import { NativeSelect } from "@/components/ui/native-select"

export function NativeSelectWithLabel() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <div className="flex w-full max-w-sm flex-col gap-1.5">
        <Label htmlFor="native-select-demo">Package manager</Label>
        <NativeSelect id="native-select-demo" defaultValue="pnpm">
          <option value="pnpm">pnpm</option>
          <option value="npm">npm</option>
          <option value="yarn">yarn</option>
          <option value="bun">bun</option>
        </NativeSelect>
      </div>
    </div>
  )
}

With hint

Start from an unselected prompt option and describe the choice with a hint. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

import { NativeSelect } from "@/components/ui/native-select"

export function NativeSelectWithHint() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-country`}>Country</FieldLabel>
        <NativeSelect
          id={`${id}-country`}
          autoComplete="country"
          defaultValue=""
          aria-describedby={`${id}-country-hint`}
        >
          <option value="" disabled>Select a country</option>
          <option value="AR">Argentina</option>
          <option value="BR">Brazil</option>
          <option value="CA">Canada</option>
          <option value="DE">Germany</option>
          <option value="JP">Japan</option>
          <option value="US">United States</option>
        </NativeSelect>
        <FieldDescription id={`${id}-country-hint`}>
          Decides the taxes shown at checkout.
        </FieldDescription>
      </Field>
    </div>
  )
}

Invalid

Associate native select validation feedback with the control. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldError, FieldLabel } from "@/components/ui/field"

import { NativeSelect } from "@/components/ui/native-select"

export function NativeSelectInvalid() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-month`}>Expiry month</FieldLabel>
        <NativeSelect
          id={`${id}-month`}
          autoComplete="cc-exp-month"
          required
          defaultValue=""
          className="max-w-40"
          aria-invalid
          aria-describedby={`${id}-month-error`}
        >
          <option value="">Month</option>
          {Array.from({ length: 12 }, (_, index) => (
            <option key={index} value={String(index + 1).padStart(2, "0")}>
              {String(index + 1).padStart(2, "0")}
            </option>
          ))}
        </NativeSelect>
        <FieldError id={`${id}-month-error`}>Choose the expiry month printed on the card.</FieldError>
      </Field>
    </div>
  )
}

Disabled

Inspect the unavailable control using its real disabled semantics. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

import { NativeSelect } from "@/components/ui/native-select"

export function NativeSelectDisabled() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-role`}>Role</FieldLabel>
        <NativeSelect id={`${id}-role`} defaultValue="viewer" disabled aria-describedby={`${id}-role-hint`}>
          <option value="viewer">Viewer</option>
          <option value="editor">Editor</option>
        </NativeSelect>
        <FieldDescription id={`${id}-role-hint`}>
          Guests always join as viewers.
        </FieldDescription>
      </Field>
    </div>
  )
}

Grouped options

Organize options with native optgroup headings and an unavailable option. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import * as React from "react"

import { Field, FieldDescription, FieldLabel } from "@/components/ui/field"

import { NativeSelect } from "@/components/ui/native-select"

export function NativeSelectGroupedOptions() {
  const id = React.useId()

  return (
    <div className="flex w-full max-w-sm flex-col gap-6">
      <Field>
        <FieldLabel htmlFor={`${id}-size`}>Instance size</FieldLabel>
        <NativeSelect id={`${id}-size`} defaultValue="m" aria-describedby={`${id}-size-hint`}>
          <optgroup label="General purpose">
            <option value="s">Small, 2 CPU and 4 GB</option>
            <option value="m">Medium, 4 CPU and 8 GB</option>
          </optgroup>
          <optgroup label="Memory optimized">
            <option value="l">Large, 4 CPU and 32 GB</option>
            <option value="xl" disabled>Extra large, unavailable in this region</option>
          </optgroup>
        </NativeSelect>
        <FieldDescription id={`${id}-size-hint`}>
          You can resize later without losing data.
        </FieldDescription>
      </Field>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

NativeSelect

The platform select, styled. Worth keeping beside the Radix one: on a phone the native picker beats anything rebuilt in the page.

NativeSelect props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReact.ReactNode—Represents all of the things React can render.
Inherited props (20)
NativeSelect inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLSelectElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
autoCompletestring | undefined—Native autocomplete hint appropriate to the field's actual purpose.
disabledboolean | undefined—Make the supported control unavailable through its native or primitive disabled semantics. This does not disable arbitrary child links.
formstring | undefined—ID of the form associated with this control, including when it is rendered outside that form element.
multipleboolean | undefined—Allow multiple values where the native element or primitive supports them, using its source-defined value shape.
namestring | undefined—Name used by the control's form submission or primitive form integration.
requiredboolean | undefined—Mark this control as required using its native or primitive semantics. Consumers own contextual validation feedback.
valuestring | number | readonly string[] | undefined—Current value in the shape defined by the source type. For controlled interactive inputs, apply updates from the change callback.
onChangeReact.ChangeEventHandler<HTMLSelectElement, HTMLSelectElement> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLSelectElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLSelectElement> | undefined—Receive the native blur event when focus leaves this control.
onKeyDownReact.KeyboardEventHandler<HTMLSelectElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLSelectElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLSelectElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

Accessibility & usage

From registry/ui/native-select.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Mobile-first forms, where the operating system picker is faster and familiar.
  • Long, familiar lists such as countries, months or years, where autofill and typeahead help.
  • Forms that must work without JavaScript or with native form submission.

When not to use

  • Options that need custom content such as icons or descriptions.
  • Lists people want to search by any part of the name; use a combobox.
  • Choosing several values.

Anatomy

NativeSelect
A wrapper with a native select element and a decorative chevron. Native attributes (name, value, onChange, required, autoComplete) pass to the select; aria-invalid shows the error border.
option and optgroup
Native children; optgroup adds group headings and disabled options stay visible.
Label and hint
A Label or FieldLabel with htmlFor, plus hint or error referenced from aria-describedby.

Keyboard & interaction

  • Keyboard, typeahead and the picker are provided by the browser and operating system.
  • On phones the platform picker opens (a wheel or a sheet), sized for touch.
  • Changes fire the native change event; controlled usage takes value and onChange.
  • Disabled selects leave the Tab order.

Responsive behavior

  • Full width, 40 CSS px high; the chevron is decorative and does not block clicks.
  • Use a max-width class for short values such as a month so the field length hints at the content.
  • Option text is rendered by the platform; long options are truncated in the closed field, so keep them short.

Content guidelines

  • Label names the value ('Country'); the empty first option prompts the choice ('Select a country').
  • Use autoComplete (country, cc-exp-month, bday-month) so browsers can fill the value (WCAG 1.3.5).
  • Error: ask for the missing choice in plain terms ('Choose the expiry month printed on the card').

Alternatives

  • Select — A styled popup with groups and custom item content.
  • Combobox — Searching a long list by any part of the label.
  • Radio group — A few options visible at once.

Resources