组件

Native Select

The browser's own <select> in a hand-drawn frame with a pencil chevron. You keep the platform's popup, mobile picker, typeahead and autofill, and a list of hundreds of options costs nothing. Reach for Select when you want the paper slip.

安装

terminal
npx shadcn@latest add @wobko/native-select

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

The browser's own select in a hand-drawn frame: its popup, its mobile picker, its typeahead. The chevron is drawn; a first option with an empty value reads as a placeholder.

Groups, sizes and states

Option groups, a small size, an invalid select (red pencil box and a bang before the chevron) and a disabled one (dashed, pale).

Shipping form

A real-world use: a native select next to inputs in a form. It submits and resets like any select, `required` stops an empty submit, and the second select follows the first.

Status

shadcn's `native-select-demo`: the browser's own `<select>` with a first option whose value is empty, which reads as the placeholder. Its list, keyboard and phone picker are the platform's.

Option groups

shadcn's `native-select-groups`: `NativeSelectOptGroup` is an `<optgroup>`, so the platform draws the group headings and indents the options under them.

Disabled

shadcn's `native-select-disabled`: `disabled` on the select. The frame is drawn dashed and pale and the chevron fades with it.

Invalid

shadcn's `native-select-invalid`: `aria-invalid="true"` redraws the frame in red pencil with a bang before the chevron. It is the same attribute a form library sets.

API 参考

NativeSelect

A `<span data-slot="native-select-wrapper">` (the drawn frame, the ink host) around the real `<select data-slot="native-select">` and a chevron. `ref` and every prop go to the select; `className` and `style` go to the frame, except padding and control-only variants (`focus:`, `disabled:` ...).

属性类型默认值说明
size"default" | "sm""default"36 px or 32 px tall (28 px in calm density). Not the HTML `size` attribute; use `multiple` for a list box.
aria-invalidboolean | "true" | "false"-true draws the red pencil box, a wavy underline and a bang before the chevron.
disabledboolean-Dashed pencil on a pale wash.
seedstring | number-Pins the hand: the same seed always draws the same box. Default: derived from useId().

无障碍

  • It is a native select: role=combobox / listbox, the platform's keyboard (arrows, typeahead, Enter, Escape), its own mobile picker, autofill and form value. Nothing is re-implemented.
  • Label it with a Label (`htmlFor` + `id`) or `aria-label`. A first option with an empty value reads as a placeholder (graphite text) when it is selected.
  • The frame follows the select's own state: keyboard focus draws the blue ring, `aria-invalid` the red box, `disabled` the dashed one. The popup itself cannot be styled by any library; only its colors and font are asked for.
  • The chevron is decorative (aria-hidden) and does not take the pointer, so the whole box opens the list. Windows high contrast replaces the ink by a real border.
  • Right-to-left: the chevron cell, the divider tick and the bang are on the start side.

源码

CLI 会复制进你项目的文件。

正在加载源码