Skip to content

Commit 6f47d56

Browse files
committed
fix: a11y fixes
1 parent 060b487 commit 6f47d56

File tree

7 files changed

+29
-73
lines changed

7 files changed

+29
-73
lines changed

src/Multiselect.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
:class="classList.group"
166166
:key="key"
167167

168-
:id="ariaGroupId(group, i)"
168+
:id="ariaGroupId(group)"
169169
:aria-label="ariaGroupLabel(group)"
170170
:aria-selected="isSelected(group)"
171171
role="option"

src/composables/useA11y.js

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ export default function useScroll (props, context, dep)
1818

1919
// ============== COMPUTED ==============
2020

21-
const mainRole = computed(() => {
22-
return mode.value === 'single' ? 'select' : 'combobox'
23-
})
24-
2521
const ariaOwns = computed(() => {
2622
let texts = []
2723

@@ -103,7 +99,7 @@ export default function useScroll (props, context, dep)
10399
return texts.join('-')
104100
}
105101

106-
const ariaGroupId = (option, index) => {
102+
const ariaGroupId = (option) => {
107103
let texts = []
108104

109105
if (id && id.value) {
@@ -112,7 +108,7 @@ export default function useScroll (props, context, dep)
112108

113109
texts.push('multiselect-group')
114110

115-
texts.push(index)
111+
texts.push(option.index)
116112

117113
return texts.join('-')
118114
}
@@ -148,7 +144,6 @@ export default function useScroll (props, context, dep)
148144
})
149145

150146
return {
151-
mainRole,
152147
ariaOwns,
153148
ariaLabel,
154149
ariaPlaceholder,

src/composables/useKeyboard.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export default function useKeyboard (props, context, dep)
6767
let activeIndex
6868

6969
if (['ArrowLeft', 'ArrowRight', 'Enter'].indexOf(e.key) !== -1 && mode.value === 'tags') {
70-
tagList = [...(multiselect.value.querySelectorAll(`[data-tags] > *`)||[])].filter(e => e !== tags.value)
70+
tagList = [...(multiselect.value.querySelectorAll(`[data-tags] > *`))].filter(e => e !== tags.value)
7171
activeIndex = tagList.findIndex(e => e === document.activeElement)
7272
}
7373

@@ -184,16 +184,12 @@ export default function useKeyboard (props, context, dep)
184184
break
185185

186186
case 'ArrowLeft':
187-
if ((searchable.value && tags.value.querySelector('input').selectionStart) || e.shiftKey) {
187+
if ((searchable.value && tags.value.querySelector('input').selectionStart) || e.shiftKey || mode.value !== 'tags' || !iv.value?.length) {
188188
return
189189
}
190190

191191
e.preventDefault()
192192

193-
if (mode.value !== 'tags') {
194-
return
195-
}
196-
197193
if (activeIndex === -1) {
198194
tagList[tagList.length-1].focus()
199195
}
@@ -203,12 +199,13 @@ export default function useKeyboard (props, context, dep)
203199
break
204200

205201
case 'ArrowRight':
206-
if (activeIndex === -1 || e.shiftKey) {
202+
if (activeIndex === -1 || e.shiftKey || mode.value !== 'tags' || !iv.value?.length) {
207203
return
208204
}
209205

210206
e.preventDefault()
211207

208+
/* istanbul ignore else */
212209
if (tagList.length > activeIndex + 1) {
213210
tagList[activeIndex+1].focus()
214211
}

src/composables/useMultiselect.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export default function useMultiselect (props, context, dep)
102102
tags,
103103
tabindex,
104104
isActive,
105+
mouseClicked,
105106
blur,
106107
focus,
107108
activate,

src/composables/useOptions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,12 @@ export default function useOptions (props, context, dep)
9595
return []
9696
}
9797

98-
return filterGroups((ro.value || /* istanbul ignore next */ []).map((group) => {
98+
return filterGroups((ro.value || /* istanbul ignore next */ []).map((group, index) => {
9999
const arrayOptions = optionsToArray(group[groupOptions.value])
100100

101101
return {
102102
...group,
103+
index,
103104
group: true,
104105
[groupOptions.value]: filterOptions(arrayOptions, false).map(o => Object.assign({}, o, group[disabledProp.value] ? { [disabledProp.value]: true } : {})),
105106
__VISIBLE__: filterOptions(arrayOptions).map(o => Object.assign({}, o, group[disabledProp.value] ? { [disabledProp.value]: true } : {})),

src/composables/usePointer.js

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default function usePointer (props, context, dep)
1010

1111
// =============== METHODS ==============
1212

13-
const setPointer = (option, groupIndex = null) => {
13+
const setPointer = (option) => {
1414
if (option === undefined || (option !== null && option[disabledProp.value])) {
1515
return
1616
}
@@ -19,15 +19,7 @@ export default function usePointer (props, context, dep)
1919
return
2020
}
2121

22-
let p = option ? {
23-
...option
24-
} : option
25-
26-
if (p && p.group) {
27-
p.index = groupIndex
28-
}
29-
30-
pointer.value = p
22+
pointer.value = option
3123
}
3224

3325
const clearPointer = () => {

src/composables/usePointerAction.js

Lines changed: 17 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -39,33 +39,23 @@ export default function usePointer (props, context, dep)
3939
return pointer.value && pointer.value.group
4040
})
4141

42-
const currentGroupIndex = computed(() => {
43-
return getParentGroupIndex(pointer.value)
44-
})
45-
4642
const currentGroup = computed(() => {
47-
return groups.value[currentGroupIndex.value]
43+
return getParentGroup(pointer.value)
4844
})
4945

50-
const prevGroupIndex = computed(() => {
51-
let group = isPointerGroup.value ? pointer.value : /* istanbul ignore next */ getParentGroup(pointer.value)
52-
let groupIndex = groups.value.map(g => g[groupLabel.value]).indexOf(group[groupLabel.value])
53-
let prevGroupIndex = groupIndex - 1
54-
55-
let prevGroup = groups.value[prevGroupIndex]
46+
const prevGroup = computed(() => {
47+
const group = isPointerGroup.value ? pointer.value : /* istanbul ignore next */ getParentGroup(pointer.value)
48+
const groupIndex = groups.value.map(g => g[groupLabel.value]).indexOf(group[groupLabel.value])
49+
let prevGroup = groups.value[groupIndex - 1]
5650

5751
if (prevGroup === undefined) {
58-
prevGroupIndex = lastGroupIndex.value
52+
prevGroup = lastGroup.value
5953
}
6054

61-
return prevGroupIndex
62-
})
63-
64-
const prevGroup = computed(() => {
65-
return groups.value[prevGroupIndex.value]
55+
return prevGroup
6656
})
6757

68-
const nextGroupIndex = computed(() => {
58+
const nextGroup = computed(() => {
6959
let nextIndex = groups.value.map(g => g.label).indexOf(isPointerGroup.value
7060
? pointer.value[groupLabel.value]
7161
: getParentGroup(pointer.value)[groupLabel.value]) + 1
@@ -74,19 +64,11 @@ export default function usePointer (props, context, dep)
7464
nextIndex = 0
7565
}
7666

77-
return nextIndex
78-
})
79-
80-
const nextGroup = computed(() => {
81-
return groups.value[nextGroupIndex.value]
82-
})
83-
84-
const lastGroupIndex = computed(() => {
85-
return groups.value.length - 1
67+
return groups.value[nextIndex]
8668
})
8769

8870
const lastGroup = computed(() => {
89-
return groups.value[lastGroupIndex.value]
71+
return [...groups.value].slice(-1)[0]
9072
})
9173

9274
const currentGroupFirstEnabledOption = computed(() => {
@@ -115,8 +97,8 @@ export default function usePointer (props, context, dep)
11597

11698
const isPointed = (option) => {
11799
return (!!pointer.value && (
118-
(!option.group && pointer.value[valueProp.value] == option[valueProp.value]) ||
119-
(option.group !== undefined && pointer.value[groupLabel.value] == option[groupLabel.value])
100+
(!option.group && pointer.value[valueProp.value] == option[valueProp.value]) ||
101+
(option.group !== undefined && pointer.value[groupLabel.value] == option[groupLabel.value])
120102
)) ? true : undefined
121103
}
122104

@@ -138,18 +120,16 @@ export default function usePointer (props, context, dep)
138120

139121
const forwardPointer = () => {
140122
if (pointer.value === null) {
141-
setPointer((groupped.value && canPointGroups.value ? groups.value[0] : options.value[0]) || null, 0)
123+
setPointer((groupped.value && canPointGroups.value ? groups.value[0] : options.value[0]) || null)
142124
}
143125
else if (groupped.value && canPointGroups.value) {
144126
let nextPointer = isPointerGroup.value ? currentGroupFirstEnabledOption.value : currentGroupNextEnabledOption.value
145-
let nGroupIndex = null
146127

147128
if (nextPointer === undefined) {
148129
nextPointer = nextGroup.value
149-
nGroupIndex = nextGroupIndex.value
150130
}
151131

152-
setPointer(nextPointer || /* istanbul ignore next */ null, nGroupIndex)
132+
setPointer(nextPointer || /* istanbul ignore next */ null)
153133
} else {
154134
let next = options.value.map(o => o[valueProp.value]).indexOf(pointer.value[valueProp.value]) + 1
155135

@@ -168,29 +148,25 @@ export default function usePointer (props, context, dep)
168148
const backwardPointer = () => {
169149
if (pointer.value === null) {
170150
let prevPointer = options.value[options.value.length - 1]
171-
let pGroupIndex = null
172151

173152
if (groupped.value && canPointGroups.value) {
174153
prevPointer = lastGroupLastEnabledOption.value
175154

176155
if (prevPointer === undefined) {
177-
prevPointer = groups.value[lastGroupIndex.value]
178-
pGroupIndex = lastGroupIndex.value
156+
prevPointer = lastGroup.value
179157
}
180158
}
181159

182-
setPointer(prevPointer || null, pGroupIndex)
160+
setPointer(prevPointer || null)
183161
}
184162
else if (groupped.value && canPointGroups.value) {
185163
let prevPointer = isPointerGroup.value ? prevGroupLastEnabledOption.value : currentGroupPrevEnabledOption.value
186-
let pGroupIndex = null
187164

188165
if (prevPointer === undefined) {
189166
prevPointer = isPointerGroup.value ? prevGroup.value : currentGroup.value
190-
pGroupIndex = isPointerGroup.value ? prevGroupIndex.value : currentGroupIndex.value
191167
}
192168

193-
setPointer(prevPointer || /* istanbul ignore next */ null, pGroupIndex)
169+
setPointer(prevPointer || /* istanbul ignore next */ null)
194170
} else {
195171
let prevIndex = options.value.map(o => o[valueProp.value]).indexOf(pointer.value[valueProp.value]) - 1
196172

@@ -212,12 +188,6 @@ export default function usePointer (props, context, dep)
212188
})
213189
}
214190

215-
const getParentGroupIndex = (option) => {
216-
return groups.value.findIndex((group) => {
217-
return group.__VISIBLE__.map(o => o[valueProp.value]).indexOf(option[valueProp.value]) !== -1
218-
})
219-
}
220-
221191
// no export
222192
/* istanbul ignore next */
223193
const adjustWrapperScrollToPointer = () => {

0 commit comments

Comments
 (0)