# Native Select

The browser's own select in a drawn box: the platform picker, a drawn outline and chevron.

Docs: https://ballpoint.st9wd.com/docs/native-select

```bash
npx shadcn@latest add @ballpoint/native-select
```

```tsx
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select"

<NativeSelect defaultValue="todo">
  <NativeSelectOption value="todo">Todo</NativeSelectOption>
  <NativeSelectOption value="done">Done</NativeSelectOption>
</NativeSelect>
```

Props:

- `size`: `"default" | "sm"` (default `"default"`). Height of the box.
- `className`: `string`. Styles the drawn box (width, margins). Every other prop goes to the <select>.
- `aria-invalid`: `boolean`. Redraws the box in red pen.
- `seed`: `string | number`. Pins the drawing.

Pen settings: `draw`, `roughness`, `passes`, `radius`, `corners`, `weight`, `speed` (see Pen settings).

## Example

```tsx
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";

export default function NativeSelectDemo() {
  return (
    <NativeSelect aria-label="Status" defaultValue="" seed="ns-demo" className="w-52">
      <NativeSelectOption value="" disabled>
        Select status
      </NativeSelectOption>
      <NativeSelectOption value="todo">Todo</NativeSelectOption>
      <NativeSelectOption value="in-progress">In progress</NativeSelectOption>
      <NativeSelectOption value="done">Done</NativeSelectOption>
      <NativeSelectOption value="cancelled">Cancelled</NativeSelectOption>
    </NativeSelect>
  );
}
```

## Groups

Options under headings with NativeSelectOptGroup.

```tsx
import { NativeSelect, NativeSelectOptGroup, NativeSelectOption } from "@/components/ui/native-select";

export default function NativeSelectGroups() {
  return (
    <NativeSelect aria-label="Department" defaultValue="eng" seed="ns-groups" className="w-56">
      <NativeSelectOptGroup label="Engineering">
        <NativeSelectOption value="eng">Frontend</NativeSelectOption>
        <NativeSelectOption value="backend">Backend</NativeSelectOption>
        <NativeSelectOption value="devops">DevOps</NativeSelectOption>
      </NativeSelectOptGroup>
      <NativeSelectOptGroup label="Sales">
        <NativeSelectOption value="sales">Sales</NativeSelectOption>
        <NativeSelectOption value="support">Support</NativeSelectOption>
      </NativeSelectOptGroup>
    </NativeSelect>
  );
}
```

## Sizes and states

A shorter size, an invalid select and a disabled one.

```tsx
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { NativeSelect, NativeSelectOption } from "@/components/ui/native-select";

export default function NativeSelectStates() {
  return (
    <div className="flex w-full max-w-xs flex-col gap-6">
      <Field>
        <FieldLabel htmlFor="ns-size">Size</FieldLabel>
        <NativeSelect id="ns-size" size="sm" defaultValue="m" seed="ns-sm" className="w-full">
          <NativeSelectOption value="s">Small</NativeSelectOption>
          <NativeSelectOption value="m">Medium</NativeSelectOption>
        </NativeSelect>
        <FieldDescription>The small size is a little shorter.</FieldDescription>
      </Field>
      <Field data-invalid>
        <FieldLabel htmlFor="ns-country">Country</FieldLabel>
        <NativeSelect id="ns-country" aria-invalid defaultValue="" seed="ns-invalid" className="w-full">
          <NativeSelectOption value="" disabled>
            Choose one
          </NativeSelectOption>
          <NativeSelectOption value="fr">France</NativeSelectOption>
          <NativeSelectOption value="ma">Morocco</NativeSelectOption>
        </NativeSelect>
        <FieldError>Pick a country to carry on.</FieldError>
      </Field>
      <Field>
        <FieldLabel htmlFor="ns-disabled">Plan</FieldLabel>
        <NativeSelect id="ns-disabled" disabled defaultValue="free" seed="ns-disabled" className="w-full">
          <NativeSelectOption value="free">Free</NativeSelectOption>
        </NativeSelect>
      </Field>
    </div>
  );
}
```

## Pen settings

- `draw`: `"auto" | "mount" | "none"` (default `"auto"`). When the strokes draw themselves in: the first time they scroll into view, as soon as they render, or never (already drawn).
- `roughness`: `number` (default `1`). 0 is ruler-neat, 1 a quick confident hand, 2 a scrawl.
- `passes`: `1 | 2 | 3`. How many times an outline is gone over. Each component picks its own default.
- `radius`: `number | "full"` (default `0`). Corner radius in px; "full" draws a pill.
- `corners`: `"crossed" | "joined"` (default `"crossed"`). Square corners: sides pulled separately past each other, or the box drawn in one motion.
- `weight`: `number` (default `1`). Line weight multiplier. Also settable in CSS as --ink-weight.
- `speed`: `number` (default `1`). Drawing speed multiplier. Also settable in CSS as --ink-speed.
