Skip to content

Commit e91d2ed

Browse files
authored
Work around iOS VoiceOver labeling issue with Slider (#1398)
* Work around iOS VoiceOver labeling issue with Slider
1 parent e9c3cdc commit e91d2ed

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

packages/@react-aria/slider/src/useSlider.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,11 @@ export function useSlider(
153153
};
154154

155155
if (labelProps.htmlFor) {
156-
// Override the `for` attribute to point to the first thumb instead of the group element.
157-
labelProps.htmlFor = labelProps.htmlFor ? getSliderThumbId(state, 0) : undefined,
156+
// Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS
157+
// causes this to override the `aria-labelledby` on the thumb. This causes the first
158+
// thumb to only be announced as the slider label rather than its individual name as well.
159+
// See https://bugs.webkit.org/show_bug.cgi?id=172464.
160+
delete labelProps.htmlFor;
158161
labelProps.onClick = () => {
159162
// Safari does not focus <input type="range"> elements when clicking on an associated <label>,
160163
// so do it manually. In addition, make sure we show the focus ring.

packages/@react-aria/slider/test/useSlider.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ describe('useSlider', () => {
3030
label: 'Slider'
3131
});
3232

33-
let {props: {labelProps, containerProps}, inputProps} = result.current;
33+
let {props: {labelProps, containerProps}} = result.current;
3434

3535
expect(containerProps.role).toBe('group');
36-
expect(labelProps.htmlFor).toBe(inputProps.id);
36+
expect(labelProps.htmlFor).toBe(undefined); // https://bugs.webkit.org/show_bug.cgi?id=172464
3737
});
3838

3939
it('should have the right labels when setting aria-label', () => {

packages/@react-spectrum/slider/test/RangeSlider.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ describe('RangeSlider', function () {
4545

4646
let label = document.getElementById(labelId);
4747
expect(label).toHaveTextContent('The Label');
48-
expect(label).toHaveAttribute('for', getAllByRole('slider')[0].id);
48+
// https://bugs.webkit.org/show_bug.cgi?id=172464
49+
// expect(label).toHaveAttribute('for', getAllByRole('slider')[0].id);
50+
expect(label).not.toHaveAttribute('for');
4951

5052
// Shows value as well
5153
let output = getByRole('status');

packages/@react-spectrum/slider/test/Slider.test.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ describe('Slider', function () {
4444

4545
let label = document.getElementById(labelId);
4646
expect(label).toHaveTextContent(/^The Label$/);
47-
expect(label).toHaveAttribute('for', getByRole('slider').id);
47+
// https://bugs.webkit.org/show_bug.cgi?id=172464
48+
// expect(label).toHaveAttribute('for', getByRole('slider').id);
49+
expect(label).not.toHaveAttribute('for');
4850

4951
// Shows value as well
5052
let output = getByRole('status');

0 commit comments

Comments
 (0)