Skip to content

Commit d5fd283

Browse files
committed
feat: a11y improvements
1 parent 5fc2b57 commit d5fd283

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

src/Slider.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ declare class Slider extends Vue {
1919
tooltipPosition?: null|'top'|'bottom'|'left'|'right';
2020
lazy?: boolean;
2121
ariaLabelledby?: string;
22+
aria?: object;
2223

2324
$emit(eventName: 'change', e: {originalEvent: Event, value: any}): this;
2425
$emit(eventName: 'update', e: {originalEvent: Event, value: any}): this;

src/Slider.vue

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@
110110
required: false,
111111
default: undefined,
112112
},
113+
aria: {
114+
required: false,
115+
type: Object,
116+
default: () => ({}),
117+
},
113118
},
114119
setup(props, context)
115120
{

src/composables/useSlider.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export default function useSlider (props, context, dependencies)
99
orientation, direction, tooltips, step,
1010
min, max, merge, id, disabled, options,
1111
classes, format, lazy, ariaLabelledby,
12+
aria,
1213
} = toRefs(props)
1314

1415
// ============ DEPENDENCIES ============
@@ -55,9 +56,12 @@ export default function useSlider (props, context, dependencies)
5556
defaultOptions.connect = true
5657
}
5758

58-
if (ariaLabelledby && ariaLabelledby.value) {
59+
if ((ariaLabelledby && ariaLabelledby.value) || (aria && Object.keys(aria.value).length)) {
5960
let handles = Array.isArray(value.value) ? value.value : [value.value]
60-
defaultOptions.handleAttributes = handles.map(h => ({ 'aria-labelledby': ariaLabelledby.value, }))
61+
62+
defaultOptions.handleAttributes = handles.map(h => (Object.assign({}, aria.value, ariaLabelledby?.value ? {
63+
'aria-labelledby': ariaLabelledby.value,
64+
}: {})))
6165
}
6266

6367
if (format.value) {

tests/unit/composables/useSlider.spec.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,15 @@ describe('useSlider', () => {
134134
expect(slider.vm.slider$.options.handleAttributes).toEqual([{ 'aria-labelledby': 'label' }])
135135
})
136136

137-
it('should init aria-labelledby with multiple handles', async () => {
137+
it('should init aria attrs with multiple handles', async () => {
138138
const slider = createSlider({
139139
value: [5,10],
140-
ariaLabelledby: 'label',
140+
aria: {
141+
'aria-invalid': false
142+
}
141143
})
142144

143-
expect(slider.vm.slider$.options.handleAttributes).toEqual([{ 'aria-labelledby': 'label' },{ 'aria-labelledby': 'label' }])
145+
expect(slider.vm.slider$.options.handleAttributes).toEqual([{ 'aria-invalid': false },{ 'aria-invalid': false }])
144146
})
145147

146148
it('should emit change on slider set event', async () => {

0 commit comments

Comments
 (0)