Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(Slider): keep a caller aria-labelledby on the thumb and range group (#8781)

홍규진664877943e21
diff --git a/.changeset/slider-caller-labelledby.md b/.changeset/slider-caller-labelledby.md
new file mode 100644
index 0000000000..d23c6ea090
--- /dev/null
+++ b/.changeset/slider-caller-labelledby.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] Slider keeps a caller's `aria-labelledby`. The thumb of a single slider and the group of a range slider always replaced it with the label id, so the caller's ids never reached the accessible name. The control is now named by its label and then the caller's ids, the same order RadioList and TimeInput use.
+
+@kyu-rong
diff --git a/packages/core/src/Slider/Slider.fr10.test.tsx b/packages/core/src/Slider/Slider.fr10.test.tsx
index da9d413b08..78384e2179 100644
--- a/packages/core/src/Slider/Slider.fr10.test.tsx
+++ b/packages/core/src/Slider/Slider.fr10.test.tsx
@@ -57,3 +57,37 @@ describe('Slider range mode prop targets', () => {
expect(onPointerDown).toHaveBeenCalledOnce();
});
});
+
+describe("Slider keeps a caller's aria-labelledby", () => {
+ it('names the thumb by its label and then the caller ids', () => {
+ render(
+ <>
+ <span id="caller-name">Speaker</span>
+ <Slider
+ label="Volume"
+ value={50}
+ onChange={() => {}}
+ aria-labelledby="caller-name"
+ />
+ </>,
+ );
+ expect(
+ screen.getByRole('slider', {name: 'Volume Speaker'}),
+ ).toBeInTheDocument();
+ });
+
+ it('names the range group by its label and then the caller ids', () => {
+ render(
+ <>
+ <span id="caller-name">USD</span>
+ <Slider
+ label="Price"
+ value={[20, 80]}
+ onChange={() => {}}
+ aria-labelledby="caller-name"
+ />
+ </>,
+ );
+ expect(screen.getByRole('group', {name: 'Price USD'})).toBeInTheDocument();
+ });
+});
diff --git a/packages/core/src/Slider/Slider.tsx b/packages/core/src/Slider/Slider.tsx
index 921c30ea8c..15aae8e28a 100644
--- a/packages/core/src/Slider/Slider.tsx
+++ b/packages/core/src/Slider/Slider.tsx
@@ -44,6 +44,7 @@ import {VisuallyHidden} from '../VisuallyHidden';
import type {InputStatus} from '../Field/types';
import {mergeProps, rtlStyles} from '../utils';
import {focusOutlineStyles} from '../utils/focusOutline.stylex';
+import {joinAriaIDs} from '../utils/inputAria';
import {
getInteractionModality,
useInteractionModalityTracking,
@@ -507,6 +508,7 @@ export function Slider({ref, ...props}: SliderProps) {
onFocus,
onBlur,
id: idProp,
+ 'aria-labelledby': ariaLabelledByProp,
'aria-describedby': ariaDescribedByProp,
...restWithRange
} = props;
@@ -1015,7 +1017,10 @@ export function Slider({ref, ...props}: SliderProps) {
aria-disabled={isDisabled || undefined}
aria-invalid={status?.type === 'error' ? true : undefined}
aria-label={thumbLabel}
- aria-labelledby={!isRange ? labelID : undefined}
+ // A caller aria-labelledby names the control together with its label.
+ aria-labelledby={
+ !isRange ? joinAriaIDs(labelID, ariaLabelledByProp) : undefined
+ }
aria-describedby={
[!isRange ? ariaDescribedByProp : undefined, ariaDescribedBy]
.filter(Boolean)
@@ -1167,7 +1172,10 @@ export function Slider({ref, ...props}: SliderProps) {
disabledMessageTooltip.ref,
)}
{...(isRange
- ? {role: 'group', 'aria-labelledby': labelID}
+ ? {
+ role: 'group',
+ 'aria-labelledby': joinAriaIDs(labelID, ariaLabelledByProp),
+ }
: undefined)}
onPointerDown={after(handlePointerDown, onPointerDown)}
onPointerMove={after(handlePointerMove, onPointerMove)}