Standard select menu which expects child <Option>
components.
Select option from the list of options. Use bind:value
to bind the selected value to a variable.
<script>
import { Select } from "$lib/ui";
let pet = $state();
</script>
<Select label="Pet" name="pet" bind:value={pet}>
<Option label="Dog" value="dog" />
<Option label="Hamster" value="hamster" />
<Option label="Parrot" value="parrot" />
</Select>
<p>Pet: {pet}</p>
Pet:
Name of the select element which will be used as the key in the form data.
<Select name="direction">
<Option label="Up" value="up" />
<Option label="Down" value="down" />
</Select>
Label for the select element.
<Select label="Direction">
<Option label="Up" value="up" />
<Option label="Down" value="down" />
</Select>
Initial option shown for the select element. Default is “Select”. Set the value to "false"
or {false}
to remove the initial option.
<Select init="Choose up or down">
<Option label="Up" value="up" />
<Option label="Down" value="down" />
</Select>
Disable the select element.
<Select name="direction" disabled>
<Option label="Up" value="up" />
<Option label="Down" value="down" />
</Select>
Display error message below the select element. Also adds error styles to the select element.
<Select label="Color" error="Must select a color">
<Option label="Blue" value="blue" />
<Option label="Red" value="red" />
<Option label="Green" value="green" />
<Option label="Yellow" value="yellow" />
</Select>
Display note message below the select element.
<Select note="We'd like to know">
<Option label="Blue" value="blue" />
<Option label="Red" value="red" />
<Option label="Green" value="green" />
<Option label="Yellow" value="yellow" />
</Select>
Name | Type | Default | Description |
---|---|---|---|
name | String | name of the input field | |
label | String | Text label appears above the input field | |
init | String | Select | The non-selectable option shown by default |
disabled | Boolean | false | Disables the user from selecting |
note | String | Text note appears below select field | |
error | String | Error message for the select field | |
class | String | CSS classes declared in global scope can be applied to the outermost element | |
... | Additional props will be passed through to the HTML element enabling support for things
like on:click , etc |
Name | Type | Default | Description |
---|---|---|---|
--ui-select-font-size | Numeric | --ui-font-size , 1rem | Font size for value of field |
--ui-select-color | Color | --ui-dark , #1e293b | Text color for value of field |
--ui-select-border-width | Numeric | --ui-border-width , 1px | Border width |
--ui-select-border-color | Color | --ui-border-color , --ui-midtone , #94a3b8 | Border color |
--ui-select-border-radius | Numeric | --ui-border-radius , 3px | Border radius |
--ui-select-padding | Numeric | --ui-padding , 4px 6px | CSS padding shorthand |
--ui-select-outline-width | Numeric | --ui-outline-width , 1px | Outline width for :focus and .error |
--ui-select-outline-offset | Numeric | --ui-outline-offset , none | Outline offset for :focus and .error |
--ui-select-focus | Color | --ui-focus , --ui-midtone , #94a3b8 | Focus color applied to border and outline |
--ui-select-error | Color | --ui-error , --ui-error , #b91c1c | Error color for border, text, error note |