Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/@react-aria/slider/src/useSlider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,11 @@ export function useSlider(
};

if (labelProps.htmlFor) {
// Override the `for` attribute to point to the first thumb instead of the group element.
labelProps.htmlFor = labelProps.htmlFor ? getSliderThumbId(state, 0) : undefined,
// Ideally the `for` attribute should point to the first thumb, but VoiceOver on iOS
// causes this to override the `aria-labelledby` on the thumb. This causes the first
// thumb to only be announced as the slider label rather than its individual name as well.
// See https://bugs.webkit.org/show_bug.cgi?id=172464.
delete labelProps.htmlFor;
labelProps.onClick = () => {
// Safari does not focus <input type="range"> elements when clicking on an associated <label>,
// so do it manually. In addition, make sure we show the focus ring.
Expand Down
4 changes: 2 additions & 2 deletions packages/@react-aria/slider/test/useSlider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ describe('useSlider', () => {
label: 'Slider'
});

let {props: {labelProps, containerProps}, inputProps} = result.current;
let {props: {labelProps, containerProps}} = result.current;

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

it('should have the right labels when setting aria-label', () => {
Expand Down
4 changes: 3 additions & 1 deletion packages/@react-spectrum/slider/test/RangeSlider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ describe('RangeSlider', function () {

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

// Shows value as well
let output = getByRole('status');
Expand Down
4 changes: 3 additions & 1 deletion packages/@react-spectrum/slider/test/Slider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ describe('Slider', function () {

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

// Shows value as well
let output = getByRole('status');
Expand Down