Alert Avatar AvatarGroup Button ButtonGroup Checkbox CheckboxGroup FilePicker Form FormRow Hamburger Input Modal Option Radio RadioGroup Rating Select Spinner Textarea Toast Tooltip Toggle

Select

Standard select menu which expects child <Option> components.

Example

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

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

Label for the select element.

<Select label="Direction">
  <Option label="Up" value="up" />
  <Option label="Down" value="down" />
</Select>

Init

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>

Disabled

Disable the select element.

<Select name="direction" disabled>
  <Option label="Up" value="up" />
  <Option label="Down" value="down" />
</Select>

Error

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>
Must select a color

Note

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>
We'd like to know

Select Component Props

Name Type Default Description
nameString name of the input field
labelString Text label appears above the input field
initStringSelectThe non-selectable option shown by default
disabledBooleanfalseDisables the user from selecting
noteString Text note appears below select field
errorString Error message for the select field
classString 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

Select CSS Custom Properties

Name Type Default Description
--ui-select-font-sizeNumeric--ui-font-size, 1remFont size for value of field
--ui-select-colorColor--ui-dark, #1e293bText color for value of field
--ui-select-border-widthNumeric--ui-border-width, 1pxBorder width
--ui-select-border-colorColor--ui-border-color, --ui-midtone, #94a3b8Border color
--ui-select-border-radiusNumeric--ui-border-radius, 3pxBorder radius
--ui-select-paddingNumeric--ui-padding, 4px 6pxCSS padding shorthand
--ui-select-outline-widthNumeric--ui-outline-width, 1pxOutline width for :focus and .error
--ui-select-outline-offsetNumeric--ui-outline-offset, noneOutline offset for :focus and .error
--ui-select-focusColor--ui-focus, --ui-midtone, #94a3b8Focus color applied to border and outline
--ui-select-errorColor--ui-error, --ui-error, #b91c1cError color for border, text, error note