WlSelect

Dropdown list with keyboard navigation.
Components / Inputs v0.1.0

Selection

Full example
<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>

Size and density

Full example
<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>

Example data

Full example
<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>

States

Full example
<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.

5,000 options

Set virtual to window a large option list. Options and group headings use the same fixed height, and keyboard navigation continues through the full filtered list.

Full example
<script setup lang="ts">
import { WlButton, WlField, WlSelect } from "legato-ui";
import { computed, 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" }];
const largeOptions = computed(() => Array.from({ length: 5000 }, (_, index) =>
  ["Record", index + 1].join(" ")
));
</script>

<template>
  <div class="wl-stack" data-space="xl" data-input-example="WlSelect">
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-subheading">{{ "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-subheading">{{ "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>
    <section class="wl-stack" data-space="md">
      <h3 class="wl-text-subheading">{{ "5,000 options" }}</h3>
      <WlSelect
        aria-label="5,000 options"
        :options="largeOptions"
        virtual
        filter
        clearable
      />
      <p class="wl-text-small wl-text-muted">{{ "Set virtual to window a large option list. Options and group headings use the same fixed height, and keyboard navigation continues through the full filtered list." }}</p>
    </section>
  </div>
</template>