A styled native select. It opens the browser's own picker, which suits mobile screens and long option lists, and needs no JavaScript. Use Select when you need custom option content or search.
<script lang="ts">
import { NativeSelect, NativeSelectOption } from "#lib/components/ui/native-select/index.js";
</script>
<NativeSelect>
<NativeSelectOption value="">Select status</NativeSelectOption>
<NativeSelectOption value="todo">Todo</NativeSelectOption>
<NativeSelectOption value="in-progress">In progress</NativeSelectOption>
<NativeSelectOption value="done">Done</NativeSelectOption>
</NativeSelect>pnx remote0 add https://plainsv.com/r/native-select.jsonWrap options in NativeSelectOptGroup and set its label to group them under a heading.
<NativeSelect>
<NativeSelectOptGroup label="Engineering">
<NativeSelectOption value="frontend">Frontend</NativeSelectOption>
<NativeSelectOption value="backend">Backend</NativeSelectOption>
</NativeSelectOptGroup>
</NativeSelect>Use bind:value to read and set the selected option. Other attributes, such as name, id, required, and onchange, pass through to the select.
Value: todo
<script lang="ts">
import { NativeSelect, NativeSelectOption } from "#lib/components/ui/native-select/index.js";
let status = $state("todo");
</script>
<NativeSelect bind:value={status}>
<NativeSelectOption value="todo">Todo</NativeSelectOption>
<NativeSelectOption value="done">Done</NativeSelectOption>
</NativeSelect>Set size to xs, sm, md, or lg. The default is md, the height matches the input of the same size, and the corner radius follows the size.
<NativeSelect size="sm">...</NativeSelect>Set rounded to xs through 4xl or pill to override the radius that follows size.
<NativeSelect rounded="pill">...</NativeSelect>Set disabled to dim the select and block it. Set aria-invalid="true" to show the invalid ring.
<NativeSelect disabled>...</NativeSelect>
<NativeSelect aria-invalid="true">...</NativeSelect>NativeSelect extends the native select attributes, except the numeric size attribute, which is replaced by the shared size scale. The class goes on the wrapper that holds the select and the chevron. NativeSelectOption and NativeSelectOptGroup extend the option and optgroup attributes.
interface Props extends Omit<CompPropsWithChild<"select">, "size" | "value"> {
/** Value of the selected option; supports `bind:value` */
value?: CompPropsWithChild<"select">["value"];
/** Height, padding, and text size on the shared scale; defaults to `md` */
size?: UiSize;
/** Corner radius; follows `size` when omitted */
rounded?: UiRounded;
}