WlSelect
Change props to see the result: the example and code use the same settings. “Reset” restores the initial values.
Settings
Field size.
Density.
Placeholder.
Error state.
Disables the field.
List animation; defaults to WlConfig.motion (true).
Show a named clear button; clears a single model to null.
Enable local filtering of available options.
Indicate pending work supplied by the application.
Choose a dataset or edit the array in the SFC below.
Props options, optionLabel, optionValue, pt, optionDisabled, optionKey, optionGroupLabel, optionGroupChildren, models, handlers and slots can be edited in the SFC. See their descriptions in API.
Example
Explore the live example and copy its Vue SFC into your application. Settings on the left can be combined.
Code for your application
Vue SFC · current settings
<script setup lang="ts">
import { WlSelect } from "legato-ui";
import { computed, ref } from "vue";
const value = ref<string | null>("team");
const options = computed(() => [{
label: "Scope",
items: [
{ label: "Team", value: "team", disabled: false },
{ label: "Personal", value: "personal", disabled: false },
{ label: "Research", value: "research", disabled: true }
]
}]);
</script>
<template>
<div class="wl-stack" data-space="md">
<WlSelect
v-model="value"
:options="options"
option-group-label="label"
option-group-children="items"
option-label="label"
option-value="value"
option-disabled="disabled"
filter
clearable
aria-label="Scope"
/>
</div>
</template>Object options and states
Separate label/id, three sizes and compact, accessible names, error, disabled and external clearing.
Sizes, density and object options
The model stores id; the list shows label. Arrow keys move the highlight, Enter selects and Escape closes the list.
Error, disabled and clearing
Model value: team.
Vue SFC · additional example
<script setup lang="ts">
import { WlButton, WlField, WlSelect } from "legato-ui";
import { ref } from "vue";
const area = ref<string | null>("team");
const options = [{ id: "personal", label: "Personal space" }, { id: "team", label: "Team" }, { id: "public", label: "Public materials" }];
</script>
<template>
<div class="wl-stack" data-space="xl" data-input-example="WlSelect">
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "Sizes, density and object options" }}</h3>
<div class="wl-grid" data-space="lg">
<WlField
v-for="size in ['sm', 'md', 'lg'] as const"
:id="`docs-select-${size}`"
:key="size"
v-slot="{ id }"
:label="`${'Space, '}${size}`"
><WlSelect
:id="id"
v-model="area"
:size="size"
:aria-label="`${'Space, '}${size}`"
:options="options"
option-label="label"
option-value="id"
placeholder="Choose a space"
/></WlField>
<WlField id="docs-select-compact" v-slot="{ id }" label="Compact list"><WlSelect
:id="id"
v-model="area"
density="compact"
aria-label="Compact list"
:options="options"
option-label="label"
option-value="id"
placeholder="Choose a space"
/></WlField>
</div>
<p class="wl-text-small wl-text-muted">{{ "The model stores id; the list shows label. Arrow keys move the highlight, Enter selects and Escape closes the list." }}</p>
</section>
<section class="wl-stack" data-space="md">
<h3 class="wl-text-title">{{ "Error, disabled and clearing" }}</h3>
<div class="wl-grid" data-space="lg">
<WlField
id="docs-select-required"
v-slot="{ id, ariaDescribedby, invalid }"
label="Required space"
:error="area == null ? 'Choose a space.' : undefined"
><WlSelect
:id="id"
v-model="area"
:options="options"
option-label="label"
option-value="id"
:invalid="invalid"
aria-label="Required space"
:aria-describedby="ariaDescribedby"
placeholder="Choose a space"
/></WlField>
<WlField id="docs-select-disabled" v-slot="{ id }" label="Unavailable list"><WlSelect
:id="id"
model-value="team"
:options="options"
option-label="label"
option-value="id"
aria-label="Unavailable list"
disabled
/></WlField>
</div>
<WlButton size="sm" @click="area = null">{{ "Clear selection" }}</WlButton>
<p class="wl-text-small" role="status">{{ "Model value:" }} {{ area ?? 'null' }}.</p>
</section>
</div>
</template>