Skip to content

Commit 3a65082

Browse files
authored
fix(Handle): add aria-orientation on handles (#859)
* fix(Handle): add aria-orientation on handles https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-orientation * test(Range): update test name
1 parent ecdcaaa commit 3a65082

File tree

4 files changed

+28
-0
lines changed

4 files changed

+28
-0
lines changed

src/Handles/Handle.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const Handle = React.forwardRef((props: HandleProps, ref: React.Ref<HTMLDivEleme
134134
aria-label={getIndex(ariaLabelForHandle, valueIndex)}
135135
aria-labelledby={getIndex(ariaLabelledByForHandle, valueIndex)}
136136
aria-valuetext={getIndex(ariaValueTextFormatterForHandle, valueIndex)?.(value)}
137+
aria-orientation={direction === 'ltr' || direction === 'rtl' ? 'horizontal' : 'vertical'}
137138
{...restProps}
138139
/>
139140
);

tests/Range.test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,26 @@ describe('Range', () => {
388388
test('touch', (container) => doTouchMove(container, 0, 20, 'rc-slider-track'));
389389
});
390390

391+
it('sets aria-orientation to default on the handle', () => {
392+
const { container } = render(<Slider range />);
393+
expect(container.getElementsByClassName('rc-slider-handle')[0]).toHaveAttribute(
394+
'aria-orientation',
395+
'horizontal',
396+
);
397+
});
398+
399+
it('sets aria-orientation to vertical on the handles of vertical Slider', () => {
400+
const { container } = render(<Slider range vertical defaultValue={[0, 20]} />);
401+
expect(container.getElementsByClassName('rc-slider-handle')[0]).toHaveAttribute(
402+
'aria-orientation',
403+
'vertical',
404+
);
405+
expect(container.getElementsByClassName('rc-slider-handle')[1]).toHaveAttribute(
406+
'aria-orientation',
407+
'vertical',
408+
);
409+
});
410+
391411
it('sets aria-label on the handles', () => {
392412
const { container } = render(
393413
<Slider range ariaLabelForHandle={['Some Label', 'Some other Label']} />,

tests/__snapshots__/Range.test.js.snap

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ exports[`Range should render Multi-Range with correct DOM structure 1`] = `
2424
/>
2525
<div
2626
aria-disabled="false"
27+
aria-orientation="horizontal"
2728
aria-valuemax="100"
2829
aria-valuemin="0"
2930
aria-valuenow="0"
@@ -34,6 +35,7 @@ exports[`Range should render Multi-Range with correct DOM structure 1`] = `
3435
/>
3536
<div
3637
aria-disabled="false"
38+
aria-orientation="horizontal"
3739
aria-valuemax="100"
3840
aria-valuemin="0"
3941
aria-valuenow="0"
@@ -44,6 +46,7 @@ exports[`Range should render Multi-Range with correct DOM structure 1`] = `
4446
/>
4547
<div
4648
aria-disabled="false"
49+
aria-orientation="horizontal"
4750
aria-valuemax="100"
4851
aria-valuemin="0"
4952
aria-valuenow="0"
@@ -54,6 +57,7 @@ exports[`Range should render Multi-Range with correct DOM structure 1`] = `
5457
/>
5558
<div
5659
aria-disabled="false"
60+
aria-orientation="horizontal"
5761
aria-valuemax="100"
5862
aria-valuemin="0"
5963
aria-valuenow="0"
@@ -81,6 +85,7 @@ exports[`Range should render Range with correct DOM structure 1`] = `
8185
/>
8286
<div
8387
aria-disabled="false"
88+
aria-orientation="horizontal"
8489
aria-valuemax="100"
8590
aria-valuemin="0"
8691
aria-valuenow="0"
@@ -91,6 +96,7 @@ exports[`Range should render Range with correct DOM structure 1`] = `
9196
/>
9297
<div
9398
aria-disabled="false"
99+
aria-orientation="horizontal"
94100
aria-valuemax="100"
95101
aria-valuemin="0"
96102
aria-valuenow="0"

tests/__snapshots__/Slider.test.js.snap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ exports[`Slider should render Slider with correct DOM structure 1`] = `
1616
/>
1717
<div
1818
aria-disabled="false"
19+
aria-orientation="horizontal"
1920
aria-valuemax="100"
2021
aria-valuemin="0"
2122
aria-valuenow="0"

0 commit comments

Comments
 (0)