A styled native HTML select element with consistent design system integration.
Epicenter
Local-first, open source apps
For a styled select component, see the Select component.
<script lang="ts">
import * as NativeSelect from "$lib/components/ui/native-select/index.js";
</script>
<NativeSelect.Root>
<NativeSelect.Option value="">Select status</NativeSelect.Option>
<NativeSelect.Option value="todo">Todo</NativeSelect.Option>
<NativeSelect.Option value="in-progress">In Progress</NativeSelect.Option>
<NativeSelect.Option value="done">Done</NativeSelect.Option>
<NativeSelect.Option value="cancelled">Cancelled</NativeSelect.Option>
</NativeSelect.Root> Installation
Copy and paste the following code into your project.
Usage
<script lang="ts">
import * as NativeSelect from "$lib/components/ui/native-select/index.js";
</script> <NativeSelect.Root>
<NativeSelect.Option value="">Select a fruit</NativeSelect.Option>
<NativeSelect.Option value="apple">Apple</NativeSelect.Option>
<NativeSelect.Option value="banana">Banana</NativeSelect.Option>
<NativeSelect.Option value="blueberry">Blueberry</NativeSelect.Option>
<NativeSelect.Option value="grapes" disabled>Grapes</NativeSelect.Option>
<NativeSelect.Option value="pineapple">Pineapple</NativeSelect.Option>
</NativeSelect.Root> Groups
Use NativeSelect.OptGroup to organize options into categories.
Disabled
Add the disabled prop to the NativeSelect.Root component to disable the select.
Invalid
Use aria-invalid to show validation errors and the data-invalid attribute to the Field.Field component for styling.
Native Select vs Select
- Use
NativeSelectfor native browser behavior, better performance, or mobile-optimized dropdowns. - Use
Selectfor custom styling, animations, or complex interactions.
API Reference
NativeSelect.Root
The main select component that wraps the native HTML select element.
All other props are passed through to the underlying <select> element.
<NativeSelect.Root>
<NativeSelect.Option value="option1">Option 1</NativeSelect.Option>
<NativeSelect.Option value="option2">Option 2</NativeSelect.Option>
</NativeSelect.Root> NativeSelect.Option
Represents an individual option within the select.
All other props are passed through to the underlying <option> element.
<NativeSelect.Option value="apple">Apple</NativeSelect.Option>
<NativeSelect.Option value="banana" disabled>Banana</NativeSelect.Option> NativeSelect.OptGroup
Groups related options together for better organization.
All other props are passed through to the underlying <optgroup> element.
<NativeSelect.OptGroup label="Fruits">
<NativeSelect.Option value="apple">Apple</NativeSelect.Option>
<NativeSelect.Option value="banana">Banana</NativeSelect.Option>
</NativeSelect.OptGroup>