# Native select

- **[Atoms](/components/)**

The browser's own select in the system's field style. Best on phones and for short lists.

## When to use

- **Use for**: One value from a short, fixed list, especially on phones.
- **Not for**: Long searchable lists, or options with icons.
- **Pairs with**: Field, forms and filters.

## Preview

native-select.tsx

```
import { Theme } from '@/components/klarhimmel/theme/style';
import { Field } from '@/components/klarhimmel/ui/input';
import { NativeSelect } from '@/components/klarhimmel/ui/native-select';

export default function Example() {
  return (
    <Theme theme="brand">
      <Field label="Room type">
        {(p) => (
          <NativeSelect {...p}>
            <option>Single</option>
            <option>Double</option>
          </NativeSelect>
        )}
      </Field>
    </Theme>
  );
}
```

## Import

- **CLI**

  ```
  npx shadcn add @klarhimmel/native-select @klarhimmel/input
  ```
- **Import**

  ```
  import { NativeSelect } from '@/components/klarhimmel/ui/native-select';
  ```

- **Files**: native-select.tsx, input.tsx, in components/klarhimmel/ui/. With it: button, editing, theme, utils. npm: lucide-react.
- **Render in**: Render it inside <Theme>, once near the root of your app. Tokens and fonts are scoped to it, so outside it the component is unstyled.

## Examples

- **Form**

  ```
  import { useState } from 'react';
  import { Button } from '@/components/klarhimmel/ui/button';
  import { Field } from '@/components/klarhimmel/ui/input';
  import { NativeSelect } from '@/components/klarhimmel/ui/native-select';
  
  export default function NativeSelectForm() {
    const [type, setType] = useState('double');
    return (
      <div className="flex w-full max-w-xs flex-col gap-4">
        <Field label="Room type" hint="Breakfast is included in every room.">
          {(p) => (
            <NativeSelect value={type} onChange={(e) => setType(e.target.value)} {...p}>
              <option value="single">Single</option>
              <option value="double">Double</option>
              <option value="suite">Suite</option>
            </NativeSelect>
          )}
        </Field>
        <p aria-live="polite" className="text-kh-small text-kh-muted">Chosen: {type}.</p>
        <Button variant="secondary" onClick={() => setType('double')}>Reset</Button>
      </div>
    );
  }
  ```
- **States**

  ```
  import { Field } from '@/components/klarhimmel/ui/input';
  import { NativeSelect } from '@/components/klarhimmel/ui/native-select';
  
  export default function NativeSelectStates() {
    return (
      <div className="flex w-full max-w-xs flex-col gap-4">
        <Field label="Arrival month" error="Pick a month to continue.">
          {(p) => (
            <NativeSelect defaultValue="" {...p}>
              <option value="" disabled>Choose a month</option>
              <option>June</option>
              <option>July</option>
            </NativeSelect>
          )}
        </Field>
        <Field label="Country">
          {(p) => (
            <NativeSelect disabled defaultValue="se" {...p}>
              <option value="se">Sweden</option>
            </NativeSelect>
          )}
        </Field>
      </div>
    );
  }
  ```

## Props

- **invalid**: Sets aria-invalid and the danger border.
- **native attributes**: Every native attribute of the element passes through, className included.

## Accessibility

- Space / Enter / Up / Down · Opens the browser's picker
- Type a letter · Jumps to a matching option

[Accessibility](/get-started/accessibility)

The browser draws the open list, so it is always accessible and always native.

[Previous](/components/menu)

[Next](/components/popover)
