Skip to content

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

TypeScript

fix(CheckboxList): keep a caller aria-labelledby on the group (#7717)

홍규진a32ce6b8ad26
diff --git a/.changeset/checkboxlist-caller-labelledby.md b/.changeset/checkboxlist-caller-labelledby.md
new file mode 100644
index 0000000000..6723f00bfe
--- /dev/null
+++ b/.changeset/checkboxlist-caller-labelledby.md
@@ -0,0 +1,7 @@
+---
+'@astryxdesign/core': patch
+---
+
+[fix] CheckboxList keeps a caller's `aria-labelledby`. The group always replaced it with its own label id, so the caller's ids never reached the accessible name. The group 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/CheckboxList/CheckboxList.fr10.test.tsx b/packages/core/src/CheckboxList/CheckboxList.fr10.test.tsx
index 33a43681ca..8b7dc168c3 100644
--- a/packages/core/src/CheckboxList/CheckboxList.fr10.test.tsx
+++ b/packages/core/src/CheckboxList/CheckboxList.fr10.test.tsx
@@ -1,7 +1,7 @@
// Copyright (c) Meta Platforms, Inc. and affiliates.
-import {describe, it} from 'vitest';
-import {screen} from '@testing-library/react';
+import {describe, it, expect} from 'vitest';
+import {render, screen} from '@testing-library/react';
import {expectFieldInputProps} from '../Field/fieldInputFamily.testing';
import {describeFieldInputParts} from '../Field/fieldInputFamily.render-testing';
import {CheckboxList, type CheckboxListProps} from './CheckboxList';
@@ -22,3 +22,30 @@ describeFieldInputParts('CheckboxList', {
getControl: () => screen.getByRole('group'),
inGroup: false,
});
+
+describe('CheckboxList FR10 details', () => {
+ it("names the group by its label and then a caller's aria-labelledby", () => {
+ render(
+ <>
+ <span id="caller-name">Billing</span>
+ <CheckboxList
+ label="Preferences"
+ value={[]}
+ onChange={() => {}}
+ aria-labelledby="caller-name">
+ <CheckboxListItem label="A" value="a" />
+ </CheckboxList>
+ </>,
+ );
+ const group = screen.getByRole('group');
+ const ids = group.getAttribute('aria-labelledby')?.split(' ');
+ expect(ids).toHaveLength(2);
+ expect(document.getElementById(ids?.[0] ?? '')?.textContent).toContain(
+ 'Preferences',
+ );
+ expect(ids?.[1]).toBe('caller-name');
+ expect(screen.getByRole('group', {name: 'Preferences Billing'})).toBe(
+ group,
+ );
+ });
+});
diff --git a/packages/core/src/CheckboxList/CheckboxList.tsx b/packages/core/src/CheckboxList/CheckboxList.tsx
index cbd4c7d338..b2648b4843 100644
--- a/packages/core/src/CheckboxList/CheckboxList.tsx
+++ b/packages/core/src/CheckboxList/CheckboxList.tsx
@@ -38,6 +38,7 @@ import {useTooltip} from '../Tooltip';
import * as stylex from '@stylexjs/stylex';
import {mergeProps} from '../utils';
import {themeProps} from '../utils/themeProps';
+import {joinAriaIDs} from '../utils/inputAria';
import {
CheckboxListContext,
type CheckboxListContextValue,
@@ -170,6 +171,7 @@ export function CheckboxList({
controlXstyle,
controlClassName,
controlStyle,
+ 'aria-labelledby': ariaLabelledByProp,
'aria-describedby': ariaDescribedByProp,
...restProps
}: CheckboxListProps) {
@@ -290,7 +292,8 @@ export function CheckboxList({
controlStyle,
)}
role="group"
- aria-labelledby={labelID}
+ // A caller aria-labelledby names the group together with its label.
+ aria-labelledby={joinAriaIDs(labelID, ariaLabelledByProp)}
aria-describedby={
[
ariaDescribedByProp,