Skip to content

NativeSelect

A list that opens to choose one option, drawn by the device itself. On a phone it becomes the wheel or sheet people already know.

import { NativeSelect } from '@sypnia/ui/react'

On this page
  1. One choice
  2. Groups and no default
  3. Sizes and states
  4. When to use it
  5. For everyone
  6. Props

One choice

Change the role: the hint explains what it allows.

Can change data and tables, not the team or billing.

Code
import { useState } from 'react';
import { Field, FormGrid, NativeSelect } from '@sypnia/ui/react';

export default function Basic() {
  const [role, setRole] = useState('editor');
  const can = { owner: 'Can do everything, including deleting the project.', editor: 'Can change data and tables, not the team or billing.', viewer: 'Can read data, and nothing else.' }[role];
  return (
    <FormGrid>
      <Field label="Role" hint={can}>
        <NativeSelect value={role} onChange={(e) => setRole(e.target.value)}>
          <option value="owner">Owner</option>
          <option value="editor">Editor</option>
          <option value="viewer">Viewer</option>
        </NativeSelect>
      </Field>
    </FormGrid>
  );
}

Groups and no default

Options grouped by continent, starting with nothing chosen.

Choose the one closest to your customers.

Code
import { Field, FormGrid, NativeSelect } from '@sypnia/ui/react';

// An empty first option asks for a choice instead of making one for the person.
export default function Groups() {
  return (
    <FormGrid>
      <Field label="Region" hint="Choose the one closest to your customers.">
        <NativeSelect defaultValue="">
          <option value="" disabled>Choose a region</option>
          <optgroup label="Europe">
            <option value="eu-central">Frankfurt</option>
            <option value="eu-west">Dublin</option>
          </optgroup>
          <optgroup label="Americas">
            <option value="us-east">Virginia</option>
            <option value="sa-east">São Paulo</option>
          </optgroup>
        </NativeSelect>
      </Field>
    </FormGrid>
  );
}

Sizes and states

Small and large, with an error and disabled.

Choose who owns this key.

The plan decides this value.

Code
import { Field, FormGrid, NativeSelect } from '@sypnia/ui/react';

export default function SizesAndStates() {
  return (
    <FormGrid>
      <Field label="Small, for toolbars">
        <NativeSelect size="sm" defaultValue="7"><option value="1">Last 24 hours</option><option value="7">Last 7 days</option><option value="30">Last 30 days</option></NativeSelect>
      </Field>
      <Field label="Large">
        <NativeSelect size="lg" defaultValue="usd"><option value="usd">US dollar</option><option value="eur">Euro</option><option value="cop">Colombian peso</option></NativeSelect>
      </Field>
      <Field label="With an error" error="Choose who owns this key.">
        <NativeSelect defaultValue=""><option value="" disabled>Choose a member</option><option>Laura Méndez</option><option>Diego Ruiz</option></NativeSelect>
      </Field>
      <Field label="Disabled" hint="The plan decides this value.">
        <NativeSelect disabled defaultValue="7"><option value="7">Backups kept 7 days</option></NativeSelect>
      </Field>
    </FormGrid>
  );
}

When to use it

Use it when

  • One choice from a short, plain list: a role, a region, a period.
  • The form is mostly used on phones: the platform’s own picker is the easiest to use there.
  • Sizes follow the other controls: sm in toolbars.

Do not use it when

  • There are two to four options and room to show them: Radio or SegmentedControl let the person see all of them at once.
  • The list is long and needs searching: that is a Combobox.
  • Options need an icon, a second line or several can be chosen: Select or MultiSelect.

For everyone

  • It is the native select: arrow keys change the value, typing jumps to an option, and every screen reader knows it.
  • Inside a Field it takes the label, the hint and the error by itself.
  • Start with an empty, disabled first option («Choose a region») when no default is right: the person makes the choice, not the form.

Props

NativeSelectTypeDefault
size "sm" | "md" | "lg"
  1. One choice
  2. Groups and no default
  3. Sizes and states
  4. When to use it
  5. For everyone
  6. Props

    Search pages, sections and terms