Skip to content

Commit 38d7f13

Browse files
authored
feat(slider): support aria-describedby on handles (#83)
Sync react-component/slider#1088.
1 parent 403952f commit 38d7f13

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/slider/src/Handles/Handle.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ export default defineComponent({
166166
tabIndex,
167167
ariaLabelForHandle,
168168
ariaLabelledByForHandle,
169+
ariaDescribedByForHandle,
169170
ariaRequired,
170171
ariaValueTextFormatterForHandle,
171172
classNames,
@@ -187,6 +188,7 @@ export default defineComponent({
187188
'aria-disabled': mergedDisabled,
188189
'aria-label': getIndex(ariaLabelForHandle, valueIndex!),
189190
'aria-labelledby': getIndex(ariaLabelledByForHandle, valueIndex!),
191+
'aria-describedby': getIndex(ariaDescribedByForHandle, valueIndex!),
190192
'aria-required': getIndex(ariaRequired, valueIndex!),
191193
'aria-valuetext': getIndex(ariaValueTextFormatterForHandle, valueIndex!)?.(value),
192194
'aria-orientation': direction === 'ltr' || direction === 'rtl' ? 'horizontal' : 'vertical',

packages/slider/src/Slider.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export interface SliderProps<Value extends ValueType = ValueType> {
114114
tabIndex?: number | number[]
115115
ariaLabelForHandle?: string | string[]
116116
ariaLabelledByForHandle?: string | string[]
117+
ariaDescribedByForHandle?: string | string[]
117118
ariaRequired?: boolean
118119
ariaValueTextFormatterForHandle?: AriaValueFormat | AriaValueFormat[]
119120
}
@@ -612,6 +613,7 @@ const Slider = defineComponent<SliderProps>((props = sliderDefaults, {
612613
tabIndex: tabIndex.value,
613614
ariaLabelForHandle: props.ariaLabelForHandle,
614615
ariaLabelledByForHandle: props.ariaLabelledByForHandle,
616+
ariaDescribedByForHandle: props.ariaDescribedByForHandle,
615617
ariaRequired: props.ariaRequired,
616618
ariaValueTextFormatterForHandle: props.ariaValueTextFormatterForHandle,
617619
styles: props.styles || {},

packages/slider/src/context.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { InjectionKey, Ref } from 'vue'
2-
import type { AriaValueFormat, Direction, SliderClassNames, SliderStyles } from './interface'
32
import type { IsHandleDisabled } from './hooks/useDisabled'
3+
import type { AriaValueFormat, Direction, SliderClassNames, SliderStyles } from './interface'
44
import { defineComponent, inject, provide, ref } from 'vue'
55

66
export interface SliderContextProps {
@@ -17,6 +17,7 @@ export interface SliderContextProps {
1717
tabIndex: number | number[]
1818
ariaLabelForHandle?: string | string[]
1919
ariaLabelledByForHandle?: string | string[]
20+
ariaDescribedByForHandle?: string | string[]
2021
ariaRequired?: boolean
2122
ariaValueTextFormatterForHandle?: AriaValueFormat | AriaValueFormat[]
2223
classNames: SliderClassNames
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// @vitest-environment jsdom
2+
3+
import { mount } from '@vue/test-utils'
4+
import { describe, expect, it } from 'vitest'
5+
import Slider from '../src'
6+
7+
describe('slider accessibility', () => {
8+
it('applies aria-describedby to each handle', () => {
9+
const wrapper = mount(Slider, {
10+
props: {
11+
range: true,
12+
defaultValue: [20, 80],
13+
ariaDescribedByForHandle: ['minimum-help', 'maximum-help'],
14+
},
15+
})
16+
17+
const handles = wrapper.findAll('[role="slider"]')
18+
expect(handles[0].attributes('aria-describedby')).toBe('minimum-help')
19+
expect(handles[1].attributes('aria-describedby')).toBe('maximum-help')
20+
})
21+
})

0 commit comments

Comments
 (0)