An open source design system that's fully customizable and agent ready
TypeScript
fix(RadioList): keep a caller aria-labelledby on the radiogroup (#5656)
Harjoth Kharaa61db6f030e6
diff --git a/.changeset/radiolist-caller-labelledby.md b/.changeset/radiolist-caller-labelledby.mdnew file mode 100644index 0000000000..411e718ce2--- /dev/null+++ b/.changeset/radiolist-caller-labelledby.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] RadioList keeps a caller's `aria-labelledby`. The radiogroup 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 TimeInput uses.++@harjothkharadiff --git a/apps/docsite/src/__tests__/theming-doc-projection.test.ts b/apps/docsite/src/__tests__/theming-doc-projection.test.tsindex c205a7d750..77fd001cee 100644--- a/apps/docsite/src/__tests__/theming-doc-projection.test.ts+++ b/apps/docsite/src/__tests__/theming-doc-projection.test.ts@@ -19,7 +19,7 @@ function emittedInterfaceFields(name: string): string[] {const match = new RegExp(`export interface ${name} \\{([\\s\\S]*?)\\n\\}`,).exec(source);- if (!match) throw new Error(`generate-data.mjs emits no interface ${name}`);+ if (!match) {throw new Error(`generate-data.mjs emits no interface ${name}`);}return [...match[1].matchAll(/^\s{2}([A-Za-z]+)\??:/gm)].map(m => m[1]);}diff --git a/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsx b/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsxindex b5bd120153..f5c8457745 100644--- a/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsx+++ b/apps/sandbox/src/app/(sandbox)/pages/motion-examples/page.tsx@@ -104,10 +104,7 @@ function NavigationOverlaysCard() {Modal — backdrop fade and content entry · duration-medium-max</Text><HStack gap={2}>- <Button- label="Open modal"- onClick={() => setModalOpen(true)}- />+ <Button label="Open modal" onClick={() => setModalOpen(true)} /></HStack></VStack></VStack>@@ -204,11 +201,7 @@ function MicroInteractionsCard() {</Text><HStack gap={2} wrap="wrap"><Button label="Primary" variant="primary" onClick={() => {}} />- <Button- label="Secondary"- variant="secondary"- onClick={() => {}}- />+ <Button label="Secondary" variant="secondary" onClick={() => {}} /><Button label="Ghost" variant="ghost" onClick={() => {}} /><Buttonlabel="Destructive"@@ -540,7 +533,6 @@ function ReducedMotionCard() {<VStack gap={2}><Text type="supporting" color="secondary" display="block">-Honor the OS-level prefers-reduced-motion setting; replace movementwith instant state changes. Toggle the switch to simulate.</Text>diff --git a/packages/core/src/Chat/__tests__/ChatMessageMetadata.a11y.chromium.spec.ts b/packages/core/src/Chat/__tests__/ChatMessageMetadata.a11y.chromium.spec.tsindex 0261ddcf20..a7cc32c97a 100644--- a/packages/core/src/Chat/__tests__/ChatMessageMetadata.a11y.chromium.spec.ts+++ b/packages/core/src/Chat/__tests__/ChatMessageMetadata.a11y.chromium.spec.ts@@ -395,7 +395,9 @@ test('captures narrow touch reflow in both modes', async ({browser}) => {try {const page = await context.newPage();const scenario = CASES.find(item => item.name === 'narrow-overflow');- if (!scenario) {throw new Error('Narrow metadata fixture is missing');}+ if (!scenario) {+ throw new Error('Narrow metadata fixture is missing');+ }const failures: string[] = [];for (const mode of ['light', 'dark'] as const) {failures.push(diff --git a/packages/core/src/RadioList/RadioList.fr10.test.tsx b/packages/core/src/RadioList/RadioList.fr10.test.tsxindex 743a9cf7a6..6a34e1a8e8 100644--- a/packages/core/src/RadioList/RadioList.fr10.test.tsx+++ b/packages/core/src/RadioList/RadioList.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 {RadioList, type RadioListProps} from './RadioList';@@ -22,3 +22,46 @@ describeFieldInputParts('RadioList', {getControl: () => screen.getByRole('radiogroup'),inGroup: false,});++describe('RadioList FR10 details', () => {+ it("names the radiogroup by its label and then a caller's aria-labelledby", () => {+ render(+ <>+ <span id="caller-name">Billing</span>+ <RadioList+ label="Plan"+ value="a"+ onChange={() => {}}+ aria-labelledby="caller-name">+ <RadioListItem label="A" value="a" />+ </RadioList>+ </>,+ );+ const group = screen.getByRole('radiogroup');+ const ids = group.getAttribute('aria-labelledby')?.split(' ');+ expect(ids).toHaveLength(2);+ expect(document.getElementById(ids?.[0] ?? '')?.textContent).toContain(+ 'Plan',+ );+ expect(ids?.[1]).toBe('caller-name');+ expect(screen.getByRole('radiogroup', {name: 'Plan Billing'})).toBe(group);+ });++ it('puts hidden, inert, and dir on the radiogroup', () => {+ render(+ <RadioList+ label="Plan"+ value="a"+ onChange={() => {}}+ hidden+ inert+ dir="rtl">+ <RadioListItem label="A" value="a" />+ </RadioList>,+ );+ const group = document.querySelector<HTMLElement>('[role="radiogroup"]');+ expect(group).toHaveAttribute('hidden');+ expect(group).toHaveAttribute('inert');+ expect(group).toHaveAttribute('dir', 'rtl');+ });+});diff --git a/packages/core/src/RadioList/RadioList.tsx b/packages/core/src/RadioList/RadioList.tsxindex b838fb9611..f054fa9f7b 100644--- a/packages/core/src/RadioList/RadioList.tsx+++ b/packages/core/src/RadioList/RadioList.tsx@@ -31,6 +31,7 @@ import type {InputStatus} from '../Field/types';import {useTooltip} from '../Tooltip';import {useResolvedRequired} from '../hooks/useResolvedRequired';import {composeEventHandlers, mergeProps} from '../utils';+import {joinAriaIDs} from '../utils/inputAria';import {type FieldInputBaseProps,useFieldInputStyling,@@ -216,6 +217,7 @@ export function RadioList({htmlName,children,onFocus,+ 'aria-labelledby': ariaLabelledByProp,'aria-describedby': ariaDescribedByProp,...restProps}: RadioListProps) {@@ -399,7 +401,8 @@ export function RadioList({disabledMessageTooltip.ref(el);}}role="radiogroup"- aria-labelledby={labelID}+ // A caller aria-labelledby names the group together with its label.+ aria-labelledby={joinAriaIDs(labelID, ariaLabelledByProp)}onFocus={composeEventHandlers(handleFocus, onFocus)}aria-describedby={[diff --git a/packages/core/src/TimeInput/TimeInput.fr10.test.tsx b/packages/core/src/TimeInput/TimeInput.fr10.test.tsxindex 97d588a75d..0d7fcb982a 100644--- a/packages/core/src/TimeInput/TimeInput.fr10.test.tsx+++ b/packages/core/src/TimeInput/TimeInput.fr10.test.tsx@@ -191,6 +191,21 @@ for (const [surface, presentation, selector] of SURFACES) {expect(own?.textContent).toContain('Start');});+ it('puts hidden, inert, and dir on the control', () => {+ render(+ <TimeInput+ label="Start"+ presentation={presentation}+ hidden+ inert+ dir="rtl"+ />,+ );+ expect(control(selector)).toHaveAttribute('hidden');+ expect(control(selector)).toHaveAttribute('inert');+ expect(control(selector)).toHaveAttribute('dir', 'rtl');+ });+it('keeps control* on the control box in a horizontal-labels FormLayout', () => {vi.spyOn(console, 'warn').mockImplementation(() => {});const {container} = render(