NativeSelect
Una lista que se abre para elegir una opción, dibujada por el propio dispositivo. En un celular se vuelve la rueda o la hoja que la gente ya conoce.
import { NativeSelect } from '@sypnia/ui/react'
Una opción
Cambia el rol: la pista explica lo que permite.
Can change data and tables, not the team or billing.
Código
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>
);
} Grupos y sin valor por defecto
Opciones agrupadas por continente, empezando sin nada elegido.
Choose the one closest to your customers.
Código
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>
);
} Tamaños y estados
Pequeño y grande, con un error y desactivado.
Choose who owns this key.
The plan decides this value.
Código
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>
);
} Cuándo usarlo
Úsalo cuando
- Una opción de una lista corta y simple: un rol, una región, un período.
- El formulario se usa sobre todo en celulares: el selector propio de la plataforma es el más fácil de usar allí.
- Los tamaños siguen a los demás controles:
smen barras de herramientas.
No lo uses cuando
- Hay de dos a cuatro opciones y espacio para mostrarlas: Radio o SegmentedControl dejan ver todas a la vez.
- La lista es larga y hay que buscar: eso es un Combobox.
- Las opciones necesitan un icono, una segunda línea o se pueden elegir varias: Select o MultiSelect.
Para todos
- Es el
selectnativo: las flechas cambian el valor, escribir salta a una opción, y todos los lectores de pantalla lo conocen. - Dentro de un Field toma la etiqueta, la pista y el error por sí solo.
- Empieza con una primera opción vacía y desactivada («Elige una región») cuando ningún valor por defecto sea correcto: elige la persona, no el formulario.
Props
| NativeSelect | Tipo | Por defecto |
|---|---|---|
size | "sm" | "md" | "lg" |