Skip to content

Commit 5e1fad0

Browse files
committed
1 parent 8577536 commit 5e1fad0

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

src/components/Select.vue

+16-1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
v-append-to-body
9292
class="vs__dropdown-menu"
9393
role="listbox"
94+
:aria-multiselectable="multiple"
9495
tabindex="-1"
9596
@mousedown.prevent="onMousedown"
9697
@mouseup="onMouseUp"
@@ -109,7 +110,7 @@
109110
'vs__dropdown-option--highlight': index === typeAheadPointer,
110111
'vs__dropdown-option--disabled': !selectable(option),
111112
}"
112-
:aria-selected="index === typeAheadPointer ? true : null"
113+
:aria-selected="optionAriaSelected(option)"
113114
@mouseover="selectable(option) ? (typeAheadPointer = index) : null"
114115
@click.prevent.stop="selectable(option) ? select(option) : null"
115116
>
@@ -1221,6 +1222,20 @@ export default {
12211222
)
12221223
},
12231224
1225+
/**
1226+
* Determine the `aria-selected` value
1227+
* of an option
1228+
*
1229+
* @param {Object|String} option
1230+
* @return {null|string}
1231+
*/
1232+
optionAriaSelected(option) {
1233+
if (!this.selectable(option)) {
1234+
return null
1235+
}
1236+
return String(this.isOptionSelected(option))
1237+
},
1238+
12241239
/**
12251240
* Ensures that options are always
12261241
* passed as objects to scoped slots.

tests/unit/Accessibility.spec.js

+59
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,62 @@ describe('UID', () => {
4545
expect(Select.find('#vs2__combobox').exists()).toBeTruthy()
4646
})
4747
})
48+
49+
describe('Option List', () => {
50+
it('multiselectable attribute should not be present by default', async () => {
51+
const Select = mountDefault()
52+
53+
Select.vm.open = true
54+
await Select.vm.$nextTick()
55+
56+
expect(
57+
Select.findComponent({ ref: 'dropdownMenu' }).attributes()[
58+
'aria-multiselectable'
59+
]
60+
).toEqual(undefined)
61+
})
62+
63+
it('multiselectable attribute should be true when multiple is true', async () => {
64+
const Select = mountDefault({ multiple: true })
65+
66+
Select.vm.open = true
67+
await Select.vm.$nextTick()
68+
69+
expect(
70+
Select.findComponent({ ref: 'dropdownMenu' }).attributes()[
71+
'aria-multiselectable'
72+
]
73+
).toEqual('true')
74+
})
75+
76+
it('selected attribute should be true if selected, false otherwise', async () => {
77+
const Select = mountDefault({
78+
value: 'two',
79+
})
80+
81+
Select.vm.open = true
82+
await Select.vm.$nextTick()
83+
84+
expect(
85+
Select.findAll('.vs__dropdown-option').wrappers.map(
86+
(option) => option.attributes()['aria-selected']
87+
)
88+
).toStrictEqual(['false', 'true', 'false'])
89+
})
90+
91+
it('selected attribute should be true on all selected options when multiple is true, false otherwise', async () => {
92+
const Select = mountDefault({
93+
multiple: true,
94+
value: ['one', 'two'],
95+
})
96+
97+
Select.vm.open = true
98+
await Select.vm.$nextTick()
99+
100+
expect(
101+
Select.findAll('.vs__dropdown-option').wrappers.map(
102+
(option) => option.attributes()['aria-selected']
103+
)
104+
).toStrictEqual(['true', 'true', 'false'])
105+
})
106+
})

0 commit comments

Comments
 (0)