Vue.js accessible multiselect component made according to WAI-ARIA practices.
- βΏοΈ fully accessible to screen readers;
- β¨οΈ supports keyboard navigation (there really a lot of keyboard shortcuts);
- π£ type-ahead to focus option that starts with typed symbols;
- π
style agnostic, so you can style it whatever you like (but including
core.scss
is highly encouraged).
$ npm install vue-accessible-multiselect --save
$ yarn add vue-accessible-multiselect
It must be called before new Vue()
.
import Vue from 'vue'
import VueAccessibleMultiselect from 'vue-accessible-multiselect'
Vue.use(VueAccessibleMultiselect)
import Vue from 'vue'
import { VueAccessibleMultiselect } from 'vue-accessible-multiselect'
Vue.component('VueAccessibleMultiselect', VueAccessibleMultiselect)
import { VueAccessibleMultiselect } from 'vue-accessible-multiselect'
export default {
name: 'YourAwesomeComponent',
components: {
VueAccessibleMultiselect,
},
}
βΉοΈ Note! To set global options (for example
transition
for each multiselect component), you should do the following:
import { config } from 'vue-accessible-multiselect'
config.transition = {
name: 'foo',
}
β οΈ Note! Options passed locally viaprops
will always take precedence over global config options.
Default config.js
:
export default {
transition: null,
}
<template>
<vue-accessible-multiselect
v-model="value"
:options="options"
:transition="{ name: 'foo' }"
label="foo"
placeholder="bar"
disabled
></vue-accessible-multiselect>
</template>
export default {
// ...
data() {
return {
value: [],
options: [
{
value: 0,
label: 'π Grape',
},
{
value: { foo: 'bar' },
label: 'π Watermelon',
},
{
value: [1, 2, 3],
label: 'π₯ Kiwi',
},
{
value: false,
label: 'π₯ Mango',
},
{
value: true,
label: 'π Strawberry',
},
{
value: 'lemon',
label: 'π Lemon',
},
],
}
},
// ...
}
After that don't forget to include core styles. Note that library is sipped with default theme styles you can use.
SASS
:
// recommended
@import 'vue-accessible-multiselect/src/styles/core.scss';
// optional
@import 'vue-accessible-multiselect/src/styles/themes/default.scss';
Or already compiled CSS
:
/* recommended */
@import 'vue-accessible-multiselect/dist/styles/core.scss';
/* optional */
@import 'vue-accessible-multiselect/dist/styles/themes/default.scss';
β οΈ Note! When you import already compiled CSS you don't have ability to overrideSASS
variables during build process, so it is preferable to use.scss
file.
core.scss
, contains some SASS
variables you can override during build process:
$v-multiselect-menu-position-top: 100% !default;
$v-multiselect-arrow-size: 8px !default;
/themes/default.scss
SASS
variables are listed here.
<vue-accessible-multiselect>
accepts some props
:
Prop | Description |
---|---|
options: array |
required . Array of multiselect options. Should be an array of objects that match the following pattern { value: any, label: string } |
value: array |
required . Current value of multiselect. |
label: string |
Multiselect label |
placeholder: string |
Multiselect placeholder |
disabled: boolean |
Whether multiselect is disabled |
transition: object |
Through this object you can configure the transition of .v-multiselect__menu entrance and leave. Should match the following pattern { name: string, mode: string? } |
<vue-accessible-multiselect>
provides you with some slots
and scopedSlots
you can use to fit your needs.
Slot | Scope | Description |
---|---|---|
label |
Label slot | |
prepend |
Prepend slot | |
placeholder |
{ placeholder } |
Placeholder slot |
selected |
{ value, options } |
Selected slot |
arrow |
Arrow slot | |
option |
{ value, option } |
Option slot |
no-options |
No options slot |
<vue-accessible-multiselect>
<template v-slot:prepend>
<svg viewBox="0 0 54 54">
<path d="M27 1l8 17 19 3-14 13 4 19-17-9-17 9 3-19L0 21l19-3z" />
</svg>
</template>
<template v-slot:label
>π Select one of the following options:</template
>
<template v-slot:placeholder
>π Select one of the following options</template
>
<template v-slot:arrow>π</template>
<template v-slot:selected="{ value, options }">π₯ Woooow, {{ value }}</template>
<template v-slot:option="{ option }"
>{{ option.label }}</template
>
</vue-accessible-multiselect>
<vue-accessisble-select>
is fully accessible when it comes to keyboard interaction.
Here is some useful keys and their appropriate actions:
Down Arrow
Moves focus to the next optionUp Arrow
Moves focus to the previous optionHome
Moves focus to first optionEnd
Moves focus to last optionSpace
Changes the selection state of the focused optionShift + Down Arrow
Moves focus to and toggles the selected state of the next optionShift + Up Arrow
Moves focus to and toggles the selected state of the previous optionShift + Space
Selects contiguous items from the most recently selected item to the focused itemControl + Shift + Home
Selects the focused option and all options up to the first option. Moves focus t first option.Control + Shift + End
Selects the focused option and all options down to the last option. Moves focus t last optionControl + A
Selects all options in the list. If all options are selected, unselects all options
Type ahead:
- Type a character: focus moves to the next option with a label that starts with the typed character;
- Type multiple characters in rapid succession: focus moves to the next option with a label that starts with the string of characters typed.
Jest
and VueTestUtils
is used for unit tests.
You can run unit tests by running next command:
npm run test:unit
- Clone this repository
- Install dependencies using
yarn install
ornpm install
- Start development server using
npm run dev
- To build production ready build simply run
npm run build
:
After successful build the following dist
folder will be generated:
βββ styles
β βββ themes
β β βββ default.css
β βββ core.css
βββ vue-accessible-multiselect.common.js
βββ vue-accessible-multiselect.esm.js
βββ vue-accessible-multiselect.js
βββ vue-accessible-multiselect.min.js
Rollup
(and plugins)Babel
SASS
andnode-sass
PostCSS
Autoprefixer
Jest
Vue Test Utils
keycode-js
lodash