Select

Usage

<Select
	label="Fruit"
	variant="outlined"
	name="fruit"
	options={[
		{ value: '', label: '' },
		{ value: 'apple', label: 'Apple', selected: true },
		{ value: 'apricot', label: 'Apricot' },
		{ value: 'banana', label: 'Banana' },
	]}
/>
<Select
	label="Fruit"
	name="fruit"
	options={[
		{ value: '', label: '', selected: true },
		{ value: 'apple', label: 'Apple' },
		{ value: 'apricot', label: 'Apricot' },
		{ value: 'banana', label: 'Banana' },
	]}
/>

Disabled

Validation

<Select
	label="Fruit"
	variant="outlined"
	name="fruit"
	disabled
	options={[{ value: '', label: '' }]}
/>
<Select
	label="Fruit"
	name="fruit"
	disabled
	options={[{ value: '', label: '', selected: true }]}
/>

Icons

<Select
	label="Favorite fruit"
	variant="outlined"
	name="fruit"
	options={[
		{ value: '', label: '' },
		{ value: 'apple', label: 'Apple' },
		{ value: 'apricot', label: 'Apricot' },
		{ value: 'banana', label: 'Banana' },
	]}
>
	{#snippet start()}
		<Icon>favorite</Icon>
	{/snippet}
</Select>

Theming

Filled select tokens

TokenDefault value
--np-filled-select-text-field-container-shape--np-shape-corner-extra-small
--np-filled-select-text-field-container-color--np-color-surface-container-highest

Filled text field example

<Select
	variant="filled"
	label="Filled"
	options={[
		{ value: '', label: '', selected: true },
		{ value: 'apple', label: 'Apple' },
		{ value: 'apricot', label: 'Apricot' },
		{ value: 'banana', label: 'Banana' },
	]}
	--np-filled-select-text-field-container-shape="0"
	--np-filled-select-text-field-container-color="var(--np-color-surface-container)"
	--np-color-primary="var(--np-color-tertiary)"
/>

Outlined select tokens

TokenDefault value
--np-outlined-select-text-field-container-shape--np-shape-corner-extra-small

Outlined text field example

<Select
	variant="outlined"
	options={[
		{ value: '', label: '', selected: true },
		{ value: 'apple', label: 'Apple' },
		{ value: 'apricot', label: 'Apricot' },
		{ value: 'banana', label: 'Banana' },
	]}
	label="Outlined"
	--np-outlined-select-text-field-container-shape="0"
	--np-color-primary="var(--np-color-tertiary)"
/>

API

Attributes

AttributeTypeDefaultDescription
variant'outlined' | 'filled''filled'Defines the visual style of the select component.
labelstring | undefinedundefinedSpecifies the floating label for the select field.
startSnippet | undefinedundefinedIcon displayed at the beginning of the select field.
supportingTextstring''Provides additional information below the select, such as usage instructions.
errorbooleanfalseManually set the select to error
errorTextstring''Manually defined error text
requiredbooleanfalseIndicates whether the select field is required.
noAsteriskbooleanfalseDisables the asterisk on the floating label when the select field is required.
disabledbooleanfalseIndicates whether the select field is disabled.
...attributesHTMLAttributes<HTMLDivElement>Attributes are passed to the component container.

Bindables

AttributeTypeDescription
elementHTMLElementA reference to the root DOM element of the component. This variable is bound using bind:this, allowing direct access to the underlying HTML element for manipulation or querying within the component's logic.
valueanyValue of the underlying select