Skip to content

Drop-down list - AvSelect

✨ Introduction

The AvSelect is a Vue component enabling a user to select an item from a given list.

The drop-down list provides a list of options from which the user can choose. Only the visible part of the component is stylized: the drop-down list of options retains the browser style.

🏗️ Structure

The AvSelect consists of a set of <option> within a <select>. If an option group is provided, it is rendered as an <optgroup> containing its child options.

🏷️ Props

NameTypeDefaultMandatoryDescription
selectedItemAvSelectSelectedOption{ itemId: '' }Selected option object used with v-model:selectedItem.
requiredbooleanfalseIndicates if the select is required.
disabledbooleanfalseIndicated if the select is disabled.
optionsAvSelectOption[][]Selectable options.
labelstring''Select text label.
namestring''Field name.
hintstring''Texte d'indice pour guider.
successMessagestring''If set, display a success message.
errorMessagestring''If set, display an error message.
placeholderstringPlaceholder text.
idstringselect-${crypto.randomUUID()}Unique id for the select. Used for the accessibility.
densebooleanfalseDense mode for reduced padding.
prefixIconstringPrefix icon name (optional).

N.B. The options prop is an array of objects with the following structure:

ts
export interface AvSelectOptionBase {
  id: string
  label: string
  disabled?: boolean
}

export interface AvSelectSelectedOption {
  itemId: string
  parentId?: string
}

export interface AvSelectOption extends AvSelectOptionBase { children?: AvSelectOption[] }

🔊 Events

NameData (payload)Description
'update:selectedItem'AvSelectSelectedOptionEmitted when an option is selected (includes parentId when option comes from an optgroup).

🎨 Slots

None.

🚀 Storybook demos

You can find examples of use and demo of the component on its dedicated Storybook page.

💡 Examples of use

vue
<script setup lang="ts">
import { ref } from 'vue'

const selectedItem = ref({ itemId: '' })
</script>

<template>
  <AvSelect
    v-model:selected-item="selectedItem"
    :options="[
      {
        id: 'group-1',
        label: 'Group 1',
        children: [
          { id: '1', label: 'Choice 1' },
          { id: '2', label: 'Choice 2' },
        ],
      },
      { id: '3', label: 'Choice 3' },
    ]"
    placeholder="Placeholder"
  />
</template>