Skip to content
iv-ui v0.3.0

NativeSelect

since 0.2.0

A native select element with the library field treatment.

import { NativeSelect } from '@elluzion/iv-ui';

Basic

A labelled select with a placeholder and helper text.

Latency is measured from the nearest edge.

Source· svelte Show Hide
<script lang="ts">
	import { NativeSelect } from '@elluzion/iv-ui';

	let region = $state('');
</script>

<div class="field-row">
	<NativeSelect
		label="Region"
		placeholder="Choose a region"
		options={['eu-west', 'us-east', 'ap-south']}
		bind:value={region}
		helper="Latency is measured from the nearest edge."
	/>
</div>

<style>
	.field-row {
		width: 100%;
		max-width: 320px;
	}
</style>
  • Use when the platform picker is preferable to the custom Select.
  • options accepts strings or { value, label, disabled }; placeholder adds a disabled first option.
  • Pass children with <option> elements to replace options.

Option objects

Labels differ from values and individual options can be disabled.

Change the plan at any time.

Source· svelte Show Hide
<script lang="ts">
	import { NativeSelect } from '@elluzion/iv-ui';

	let plan = $state('pro');

	const options = [
		{ value: 'free', label: 'Free — 1 project' },
		{ value: 'pro', label: 'Pro — 10 projects' },
		{ value: 'team', label: 'Team — unlimited' },
		{ value: 'enterprise', label: 'Enterprise — contact us', disabled: true }
	];
</script>

<div class="field-row">
	<NativeSelect label="Plan" {options} bind:value={plan} helper="Change the plan at any time." />
</div>

<style>
	.field-row {
		width: 100%;
		max-width: 320px;
	}
</style>

States

Error and disabled treatments share the same frame.

An environment is required.

Locked by the organization policy.

Source· svelte Show Hide
<script lang="ts">
	import { NativeSelect } from '@elluzion/iv-ui';

	let errorValue = $state('');
</script>

<div class="stack">
	<NativeSelect
		label="Environment"
		placeholder="Choose an environment"
		options={['staging', 'production']}
		bind:value={errorValue}
		error="An environment is required."
	/>
	<NativeSelect
		label="Region"
		options={['eu-west', 'us-east']}
		value="eu-west"
		disabled
		helper="Locked by the organization policy."
	/>
</div>

<style>
	.stack {
		display: flex;
		flex-direction: column;
		gap: var(--iv_spacing-lg);
		width: 100%;
		max-width: 320px;
	}
</style>
import { NativeSelect } from '@elluzion/iv-ui';

Props

12 props · 1 events · 1 snippets
PropTypeDefaultDescription
options NativeSelectOption[][]Options to render. Strings are used as both value and label.
value bindablestring''Selected value. Bind with bind:value.
placeholder string''Disabled first option shown while no value is selected.
label string''Visible label above the select.
error string''Error message. Switches the control to the error treatment.
helper string''Helper text shown below the control.
name string''Form field name submitted with the surrounding form.
disabled booleanfalseDisables interaction and applies the disabled treatment.
required booleanfalseMarks the field as required.
size 'sm' | 'md' | 'lg''md'Control size.
id string''Element id. A generated id is used when omitted.
className string''Extra classes merged onto the root element.

class, id, style, aria-*, and data-* are forwarded through rest props.

Events

EventHandler typeDescription
onchange(e: Event) => voidCalled with the native change event.

The legacy on:name form is accepted for every event.

Snippets

SnippetTypeDescription
childrenSnippetCustom option elements, used instead of options.

Types

NativeSelectOption

An option value or a full option object.

type NativeSelectOption = string | { value: string; label?: string; disabled?: boolean };
KeysAction
TabMoves focus to the select.
Arrow keysMove through options in the platform picker.
Enter / SpaceOpens the picker.
  • The label is associated through a generated id, or pass id explicitly.
  • Error text is linked with aria-describedby and the select gets aria-invalid.
Class hooks
.iv-chevron.iv-disabled.iv-error-message.iv-has-error.iv-helper-message.iv-label.iv-lg.iv-message.iv-native-select.iv-required-mark.iv-sm
iv-ui
↑ ↓ navigate ↵ open esc close minisearch · 482 records