ZUI

Search documentation

Find a page or a heading.

Native select

A field that picks one of a list of options, written as HTML's select is written.

Installation

bash

The CLI writes components/ui/native-select.tsx and installs Select, with what Select installs, and Utils.

Usage

tsx
tsx
tsx

API reference

NativeSelect

Takes every prop of SelectTrigger, such as aria-label, aria-invalid and disabled, plus:

It is drawn with Select: a combobox showing the chosen option's label, with a chevron at its end, whose press opens a list of the options. Until another is chosen it shows the first option that is not disabled, as HTML's select does, so an option with an empty value, such as Select status, asks for a choice. onValueChange gets the chosen option's value, '' for an option whose value is empty. className goes to the box around the field, as upstream's goes to the box around its <select>; the other props go to the field. size="sm" draws it 32px tall rather than 36px, and aria-invalid draws the destructive border. Name it with aria-label.

NativeSelectOption

An option of the list, announced with its selected state, with a check mark while chosen. A disabled option is dimmed, announced as disabled and ignores presses.

NativeSelectOptGroup

Options under a muted heading, label, announced as a group. disabled disables every option in it.

Differences from upstream

  • Upstream draws HTML's <select>, which the browser opens in its own picker. React Native has no select element, and the platform pickers come from @react-native-picker/picker, which Expo Go does not carry. So the parts keep upstream's names and draw Select: the list opens over the screen beside the field, on a device and on the web alike, and closes on a choice, a press outside it, the back button or Escape.
  • onValueChange gets the chosen value, where upstream's onChange gets the DOM's change event: React Native has no change event for it.
  • HTML's form attributes, name, required, multiple, form and autoComplete, are left out: React Native has no form for them to join.
  • The field is as wide as the chosen option's label and its chevron, where the browser draws a select as wide as its widest option. Give it a width through className for a field that keeps its width.
  • The field is drawn by Select's trigger slot. Its height, border and radius are the native select slot's in both styles, and its chevron sits in the row after the label rather than over the field's right padding.