An open source design system that's fully customizable and agent ready
TypeScript
fix(core): wire aria-controls on ChatComposerDrawer toggle (#3996)
Baraa Hamodicf4c0a4dca0e
diff --git a/.changeset/chatcomposerdrawer-controls.md b/.changeset/chatcomposerdrawer-controls.mdnew file mode 100644index 0000000000..61e5c82ec6--- /dev/null+++ b/.changeset/chatcomposerdrawer-controls.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] Chat: the composer drawer toggle now references its disclosed content via aria-controls, so assistive tech can navigate from the toggle to the drawer.++@bhamodidiff --git a/packages/core/src/Chat/ChatComposerDrawer.test.tsx b/packages/core/src/Chat/ChatComposerDrawer.test.tsxnew file mode 100644index 0000000000..91a90ccb32--- /dev/null+++ b/packages/core/src/Chat/ChatComposerDrawer.test.tsx@@ -0,0 +1,61 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++import {describe, it, expect} from 'vitest';+import {render, screen, fireEvent} from '@testing-library/react';+import {ChatComposerDrawer} from './ChatComposerDrawer';++describe('ChatComposerDrawer', () => {+ it('links the toggle to the drawer content via aria-controls', () => {+ render(+ <ChatComposerDrawer count={2} label="Attachments">+ <span>Drawer content</span>+ </ChatComposerDrawer>,+ );++ const toggle = screen.getByRole('button', {name: /Attachments/});+ const controlsId = toggle.getAttribute('aria-controls');+ // aria-controls must be present and point at the real content region.+ expect(controlsId).toBeTruthy();+ const region = document.getElementById(controlsId as string);+ expect(region).not.toBeNull();+ expect(region).toContainElement(screen.getByText('Drawer content'));+ });++ it('keeps aria-controls resolvable while collapsed (content stays mounted)', () => {+ render(+ <ChatComposerDrawer count={2} label="Attachments" defaultIsCollapsed>+ <span>Drawer content</span>+ </ChatComposerDrawer>,+ );++ const toggle = screen.getByRole('button', {name: /Attachments/});+ const controlsId = toggle.getAttribute('aria-controls');+ expect(controlsId).toBeTruthy();+ const region = document.getElementById(controlsId as string);+ expect(region).not.toBeNull();+ expect(region).toContainElement(screen.getByText('Drawer content'));+ });++ it('toggles aria-expanded when the toggle is activated', () => {+ render(+ <ChatComposerDrawer count={2} label="Attachments">+ <span>Drawer content</span>+ </ChatComposerDrawer>,+ );++ const toggle = screen.getByRole('button', {name: /Attachments/});+ expect(toggle).toHaveAttribute('aria-expanded', 'true');++ fireEvent.click(toggle);+ expect(screen.getByRole('button', {name: /Attachments/})).toHaveAttribute(+ 'aria-expanded',+ 'false',+ );++ fireEvent.click(screen.getByRole('button', {name: /Attachments/}));+ expect(screen.getByRole('button', {name: /Attachments/})).toHaveAttribute(+ 'aria-expanded',+ 'true',+ );+ });+});diff --git a/packages/core/src/Chat/ChatComposerDrawer.tsx b/packages/core/src/Chat/ChatComposerDrawer.tsxindex b530e25744..3d1e1fe975 100644--- a/packages/core/src/Chat/ChatComposerDrawer.tsx+++ b/packages/core/src/Chat/ChatComposerDrawer.tsx@@ -9,13 +9,15 @@* @position Collapsible drawer panel for ChatComposer.* Supports expanded (full content) and collapsed (count + label) states* with fade animation and grid-template-rows height transition.+ * The collapse toggle exposes aria-expanded + aria-controls linking it to+ * the content region (disclosure pattern).** SYNC: When modified, update:* - /packages/core/src/Chat/index.ts (exports)* - /packages/cli/templates/blocks/components/ChatComposerDrawer/ (block examples)*/-import {useState, type ReactNode} from 'react';+import {useId, useState, type ReactNode} from 'react';import type {StyleXStyles} from '@stylexjs/stylex';import * as stylex from '@stylexjs/stylex';import {@@ -240,6 +242,12 @@ export function ChatComposerDrawer({const canCollapse = count != null;+ // Links the toggle to the region it shows/hides so assistive tech can move+ // from the button to its controlled content (disclosure pattern). The+ // content stays mounted while collapsed (hidden via the grid-row collapse),+ // so the reference always resolves.+ const contentId = useId();+const toggle = () => {const next = !isCollapsed;if (!isControlled) {@@ -271,6 +279,7 @@ export function ChatComposerDrawer({role="button"tabIndex={0}aria-expanded={!isCollapsed}+ aria-controls={contentId}aria-label={isCollapsed? t('@astryx.chatComposerDrawer.expand', {label})@@ -301,6 +310,7 @@ export function ChatComposerDrawer({)}<div+ id={contentId}{...stylex.props(styles.contentGrid,canCollapse && isCollapsed && styles.contentGridCollapsed,