Accessible Select Dropdown Component For Vue.js

A custom, accessible, searchable select dropdown component that supports multiple selection.

How to use it:

1. Import the component into your Vue project.

import { 
  // single selection
  SelectSingle, 
  // multiple selection
  SelectMulti, 
  // core
  SelectOption 
} from '@politico/vue-accessible-selects'

2. Add the single & multiple select components to the template.

<SelectSingle
  v-model="selectSingleValue"
  :options="myOptions"
  label="Single Select"
  :labelIsVisible="true"
  @select="handleSelectEvent"
/>
<SelectMulti
  v-model="selectMultiValues"
  :options="myOptions"
  label="Multiple Select"
  :labelIsVisible="true"
  placeholder="Placeholder"
  @select="handleSelectEvent"
  @remove="handleRemoveEvent"
  @searchChange="handleSearchChangeEvent"
/>

3. Register the component and define the data to be presented in the select.

const myOptions: SelectOption[] = [{
  label: 'Option 1',
  value: 'option1'
}, {
  label: 'Option 2',
  value: 'option2'
}, {
  label: 'Option 3',
  value: 'option3'
}]
export default Vue.extend({
  components: { SelectSingle, SelectMulti },
  data() {
    return {
      myOptions,
      selectSingleValue: {} as SelectOption,
      selectMultiValues: [] as SelectOption[]
    }
  },
  methods: {
    handleSelectEvent(selectedValue: SelectOption) {
      // do something
    },
    handleRemoveEvent(selectedValue: SelectOption) {
      // do something
    },
    handleSearchChangeEvent(inputValue: string) {
      // do something
    }
  }
})

4. All default component props.

disabled: {
  type: Boolean,
  default: false
},
label: {
  type: String,
  required: true
},
loading: {
  type: Boolean,
  default: false
},
options: {
  type: Array as PropType<SelectOption[]>,
  required: true
},
labelIsVisible: {
  type: Boolean,
  required: false,
  default: true
},
placeholder: {
  type: String,
  required: false,
  default: () => null
},
/**
 * When using a slot to display each option in the select,
 * you'll want to pass in a way for the select to *search* for those options as a user types,
 * in order to accurately filter the available options
 * @example
 * ```
 * :optionLabelForSearching="a => a.label + '-' + a.value"
 * ```
 */
optionLabelForSearching: {
  type: Function as PropType<(option: SelectOption) => string>,
  required: false,
  default: null
},
displayPillsBelowInput: {
  type: Boolean,
  default: false
},
/**
 * By default, the list will be empty when either no options are passed in,
 * or a user has typed a string that doesn't match any of the options. 
 * If you'd like to display a messsage instead when that occurs, pass it in here
 */
noResultsMessage: {
  type: String,
  default: ''
},
/** Generally, there's no need to set this via a prop - it will be set automatically when using v-model */
values: {
  type: Array as PropType<SelectOption[]>,
  required: false,
  default: () => []
}

Preview:

Accessible Select Dropdown Component For Vue.js

Changelog:

v1.8.1 (04/25/2023)

  • Bugfix

v1.8.0 (04/12/2023)

  • Bugfix

v1.7.0 (04/06/2023)

  • Bugfix

v1.6.0 (03/30/2023)

  • Bugfix

v1.5.0 (03/27/2023)

  • Bugfix

v1.4.0 (11/30/2022)

  • Bugfix

v1.3.0 (08/30/2022)

  • Add aria-label for selected option

v1.1.6 (07/25/2022)

  • fix: add aria-roledescription to inform user about multiple options

v1.1.5 (07/11/2022)

  • fix: add aria label for list

v1.1.4 (07/07/2022)

  • fix (PROJ-4856): Add aria-label for selected option

v1.1.3 (04/21/2022)

  • Change the color of placeholer

v1.1.2 (01/26/2022)

  • Add label for screen reader

v1.1.0 (12/23/2021)

  • Fix scroll jumping

v1.0.1 (12/22/2021)

  • Fix filtering when async data

v1.0.0 (11/24/2021)

  • feature (FEP-642): Change slashes to math.div in scss mixin file

v0.17.0 (07/30/2021)

  • Add optional chaining for checking key presence in getActionFromKey

v0.16.0 (04/29/2021)

  • Add default value for not required function param

v0.15.0 (04/28/2021)

  • Update

v0.14.0 (04/15/2021)

  • Add placeholder and isDisabled property for option

v0.13.1 (03/20/2021)

  • fix: Fix scroll to focused option

v0.13.0 (02/25/2021)

  • refactor

v0.12.0 (12/21/2020)

  • Update prop name

v0.11.2 (12/18/2020)

  • fix: update activeIndex after changing selectedIndex

v0.11.0 (12/12/2020)

  • feat: add loading slot

v0.10.0 (12/10/2020)

  • emit filtered options as well as input value when it changes

v0.8.2 (11/22/2020)

  • Fix changing selected option on click

v0.8.1 (11/19/2020)

  • SelectSingle – add option-selected class to selected option

v0.8.0 (11/11/2020)

  • Add a watcher on loading to invoke opening the filter options

v0.7.1 (11/07/2020)

  • Updated

v0.7.0 (10/29/2020)

  • Add loading prop. add icons slot

v0.6.0 (10/28/2020)

  • Add optional no results msg

Download Details:

Author: politico

Live Demo: https://vue-accessible-selects.netlify.app/

Download Link: https://github.com/politico/vue-accessible-selects/archive/main.zip

Official Website: https://github.com/politico/vue-accessible-selects

Install & Download:

# NPM
$ npm i @politico/vue-accessible-components

Add Comment