Skip to content

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

TypeScript

fix(lab): accessibility cleanup for CodeEditor, SankeyChart, and Schedule (#3549)

Cindy Zhang8f64eb97d5f6
diff --git a/apps/storybook/stories/CodeEditor.stories.tsx b/apps/storybook/stories/CodeEditor.stories.tsx
index e636c47308..1036089259 100644
--- a/apps/storybook/stories/CodeEditor.stories.tsx
+++ b/apps/storybook/stories/CodeEditor.stories.tsx
@@ -47,6 +47,7 @@ function ControlledEditor(
const [value, setValue] = useState(props.value ?? defaultCode);
return (
<CodeEditor
+ label="Code editor"
language="typescript"
hasLineNumbers
{...props}
diff --git a/apps/storybook/stories/CodeEditorPerf.stories.tsx b/apps/storybook/stories/CodeEditorPerf.stories.tsx
index 8e054532a2..74f6da3439 100644
--- a/apps/storybook/stories/CodeEditorPerf.stories.tsx
+++ b/apps/storybook/stories/CodeEditorPerf.stories.tsx
@@ -118,6 +118,7 @@ function StressTestImpl() {
)}
</div>
<CodeEditor
+ label="Code editor"
value={code}
onChange={setCode}
language="typescript"
@@ -208,6 +209,7 @@ function TypingLatencyImpl() {
value={code}
onChange={handleChange}
language="typescript"
+ label="Code editor"
hasLineNumbers
maxHeight={600}
/>
diff --git a/apps/storybook/stories/CodeEditorTheme.stories.tsx b/apps/storybook/stories/CodeEditorTheme.stories.tsx
index c9691d8e5a..e1be1be950 100644
--- a/apps/storybook/stories/CodeEditorTheme.stories.tsx
+++ b/apps/storybook/stories/CodeEditorTheme.stories.tsx
@@ -75,6 +75,7 @@ function ThemedEditor({
return (
<SyntaxThemeProvider theme={theme}>
<CodeEditor
+ label="Code editor"
value={value}
onChange={setValue}
language="typescript"
@@ -188,6 +189,7 @@ function GalleryEditor({
value={value}
onChange={setValue}
language="typescript"
+ label="Code editor"
hasLineNumbers
/>
</div>
diff --git a/packages/lab/src/CodeEditor/CodeEditor.test.tsx b/packages/lab/src/CodeEditor/CodeEditor.test.tsx
new file mode 100644
index 0000000000..20a04575ee
--- /dev/null
+++ b/packages/lab/src/CodeEditor/CodeEditor.test.tsx
@@ -0,0 +1,21 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import {describe, it, expect} from 'vitest';
+import {render, screen} from '@testing-library/react';
+import {CodeEditor} from './CodeEditor';
+
+describe('CodeEditor', () => {
+ it('uses the label prop as the accessible name', () => {
+ render(
+ <CodeEditor
+ value=""
+ onChange={() => {}}
+ language="typescript"
+ label="Edit snippet"
+ />,
+ );
+ expect(
+ screen.getByRole('textbox', {name: 'Edit snippet'}),
+ ).toBeInTheDocument();
+ });
+});
diff --git a/packages/lab/src/CodeEditor/CodeEditor.tsx b/packages/lab/src/CodeEditor/CodeEditor.tsx
index 747370f58d..e78bdcb4a3 100644
--- a/packages/lab/src/CodeEditor/CodeEditor.tsx
+++ b/packages/lab/src/CodeEditor/CodeEditor.tsx
@@ -131,6 +131,8 @@ export interface CodeEditorProps extends Omit<
onChange: (value: string) => void;
/** Language for highlighting. @default "plaintext" */
language?: string;
+ /** Label for the code editor — used as the accessible name of the editable region. */
+ label: string;
/** Show line numbers. @default false */
hasLineNumbers?: boolean;
/** Read-only mode. @default false */
@@ -182,6 +184,7 @@ let editorInstanceCounter = 0;
* ```tsx
* const [code, setCode] = useState('');
* <CodeEditor
+ * label="Source code"
* value={code}
* onChange={setCode}
* language="typescript"
@@ -199,6 +202,7 @@ export function CodeEditor({
maxHeight,
size = 'md',
tokenizer: customTokenizer,
+ label,
xstyle,
className,
style,
@@ -447,6 +451,7 @@ export function CodeEditor({
contentEditable={isReadOnly ? false : ('plaintext-only' as any)}
role="textbox"
aria-multiline="true"
+ aria-label={label}
aria-readonly={isReadOnly}
spellCheck={false}
onInput={handleInput}
diff --git a/packages/lab/src/Sankey/SankeyChart.test.tsx b/packages/lab/src/Sankey/SankeyChart.test.tsx
new file mode 100644
index 0000000000..c4de6967c7
--- /dev/null
+++ b/packages/lab/src/Sankey/SankeyChart.test.tsx
@@ -0,0 +1,77 @@
+// Copyright (c) Meta Platforms, Inc. and affiliates.
+
+import {describe, it, expect, beforeEach, afterEach, vi} from 'vitest';
+import {render, screen, act} from '@testing-library/react';
+import {SankeyChart} from './SankeyChart';
+import {SankeyNode} from './SankeyNode';
+
+const nodes = [
+ {id: 'a', label: 'A', value: 10},
+ {id: 'b', label: 'B', value: 10},
+ {id: 'c', label: 'C', value: 10},
+];
+const links = [
+ {source: 'a', target: 'b', value: 5},
+ {source: 'b', target: 'c', value: 5},
+];
+
+// Capture the ResizeObserver callback so tests can drive the reported width.
+let resizeCallback: ResizeObserverCallback | undefined;
+
+beforeEach(() => {
+ resizeCallback = undefined;
+ vi.stubGlobal(
+ 'ResizeObserver',
+ class {
+ constructor(cb: ResizeObserverCallback) {
+ resizeCallback = cb;
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+ },
+ );
+});
+
+afterEach(() => {
+ vi.unstubAllGlobals();
+});
+
+function reportWidth(width: number) {
+ act(() => {
+ resizeCallback?.(
+ [{contentRect: {width}} as unknown as ResizeObserverEntry],
+ {} as ResizeObserver,
+ );
+ });
+}
+
+describe('SankeyChart scroll container', () => {
+ it('is keyboard-focusable when the chart needs horizontal scrolling', () => {
+ render(
+ <SankeyChart nodes={nodes} links={links} minColumnWidth={400}>
+ <SankeyNode />
+ </SankeyChart>,
+ );
+
+ // Container narrower than the minimum column width forces scrolling.
+ reportWidth(300);
+
+ const scrollRegion = screen.getByRole('group', {name: 'Sankey chart'});
+ expect(scrollRegion).toHaveAttribute('tabindex', '0');
+ });
+
+ it('does not add a focusable scroll region when everything fits', () => {
+ render(
+ <SankeyChart nodes={nodes} links={links} minColumnWidth={50}>
+ <SankeyNode />
+ </SankeyChart>,
+ );
+
+ reportWidth(1000);
+
+ expect(
+ screen.queryByRole('group', {name: 'Sankey chart'}),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/packages/lab/src/Sankey/SankeyChart.tsx b/packages/lab/src/Sankey/SankeyChart.tsx
index 5892fead05..acd4f3b84e 100644
--- a/packages/lab/src/Sankey/SankeyChart.tsx
+++ b/packages/lab/src/Sankey/SankeyChart.tsx
@@ -202,6 +202,9 @@ export function SankeyChart({
<div ref={containerRef} style={{width: '100%'}}>
{ctx && (
<div
+ role={needsScroll ? 'group' : undefined}
+ aria-label={needsScroll ? 'Sankey chart' : undefined}
+ tabIndex={needsScroll ? 0 : undefined}
style={
needsScroll ? {overflowX: 'auto', overflowY: 'hidden'} : undefined
}>
diff --git a/packages/lab/src/Schedule/ListView.tsx b/packages/lab/src/Schedule/ListView.tsx
index 37b33cf095..0cb6754323 100644
--- a/packages/lab/src/Schedule/ListView.tsx
+++ b/packages/lab/src/Schedule/ListView.tsx
@@ -52,7 +52,7 @@ export interface ScheduleListViewOptions {
function ScheduleListView(
_props: ScheduleViewComponentProps<ScheduleListViewOptions>,
) {
- const {events, timezoneID, range, isLoading} = useScheduleContext();
+ const {events, timezoneID, range, isLoading, headingLevel} = useScheduleContext();
const days = enumerateDates(range.startDate, range.endDate);
const currentTime = useCurrentTime();
const currentPlainDate = plainDateFromInstant(currentTime, timezoneID);
@@ -97,6 +97,7 @@ function ScheduleListView(
day={day}
isCurrentDay={isCurrentDay}
timezoneID={timezoneID}
+ headingLevel={headingLevel}
/>
<div {...stylex.props(styles.listEvents)}>
{renderListRows({
@@ -117,14 +118,16 @@ function ListDayHeading({
day,
isCurrentDay,
timezoneID,
+ headingLevel,
}: {
day: PlainDate;
isCurrentDay: boolean;
timezoneID: string;
+ headingLevel: 2 | 3 | 4 | 5 | 6;
}) {
return (
<Heading
- level={4}
+ level={headingLevel}
color="secondary"
display="block"
aria-label={formatFullDate(day, timezoneID)}
diff --git a/packages/lab/src/Schedule/MonthlyView.tsx b/packages/lab/src/Schedule/MonthlyView.tsx
index 471b4da87b..4b586c55a3 100644
--- a/packages/lab/src/Schedule/MonthlyView.tsx
+++ b/packages/lab/src/Schedule/MonthlyView.tsx
@@ -57,7 +57,7 @@ export interface ScheduleMonthlyViewOptions {
function ScheduleMonthlyView(
_props: ScheduleViewComponentProps<ScheduleMonthlyViewOptions>,
) {
- const {events, categories, date, focusDate, timezoneID, range, isLoading} =
+ const {events, categories, date, focusDate, timezoneID, range, isLoading, headingLevel} =
useScheduleContext();
const rangeDate = date.toPlainDate();
const highlightedDate = focusDate.toPlainDate();
@@ -86,7 +86,7 @@ function ScheduleMonthlyView(
aria-colindex={index + 1}
{...stylex.props(styles.weekdayLabel)}>
<Heading
- level={4}
+ level={headingLevel}
color="secondary"
display="block"
xstyle={styles.weekdayHeading}>
diff --git a/packages/lab/src/Schedule/Schedule.test.tsx b/packages/lab/src/Schedule/Schedule.test.tsx
index 0b2e08a4cd..b5646ab164 100644
--- a/packages/lab/src/Schedule/Schedule.test.tsx
+++ b/packages/lab/src/Schedule/Schedule.test.tsx
@@ -99,6 +99,45 @@ describe('Schedule', () => {
expect(screen.queryByText('Outside range')).not.toBeInTheDocument();
});
+ it('renders monthly weekday headings at the configured headingLevel (default 3)', async () => {
+ render(
+ <Schedule
+ view={createScheduleMonthlyView()}
+ events={events}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ focusDate={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText('Visible sync')).toBeInTheDocument();
+ });
+ expect(
+ screen.getAllByRole('heading', {level: 3}).length,
+ ).toBeGreaterThan(0);
+ });
+
+ it('renders list day headings at the configured headingLevel (default 3)', async () => {
+ render(
+ <Schedule
+ view={createScheduleListView({days: 7})}
+ events={events}
+ categories={categories}
+ date={Date.UTC(2026, 4, 13)}
+ timezoneID="UTC"
+ />,
+ );
+
+ await waitFor(() => {
+ expect(screen.getByText('Visible sync')).toBeInTheDocument();
+ });
+ expect(
+ screen.getAllByRole('heading', {level: 3}).length,
+ ).toBeGreaterThan(0);
+ });
+
it('loads async events with Instant range boundaries', async () => {
const loader = vi.fn(
async (_start: Instant, _end: Instant) =>
diff --git a/packages/lab/src/Schedule/Schedule.tsx b/packages/lab/src/Schedule/Schedule.tsx
index e26dc21b53..18c538579f 100644
--- a/packages/lab/src/Schedule/Schedule.tsx
+++ b/packages/lab/src/Schedule/Schedule.tsx
@@ -56,6 +56,8 @@ export interface ScheduleProps<
timezoneID?: string;
/** Header/rendering plugins. Defaults to pagination controls. */
plugins?: ReadonlyArray<SchedulePlugin>;
+ /** Heading level for sub-headings (day labels, weekday headers) within the schedule. @default 3 */
+ headingLevel?: 2 | 3 | 4 | 5 | 6;
}
interface EventRecord {
@@ -158,6 +160,7 @@ function ScheduleViewContent<Options extends ScheduleViewOptions>({
onNextDate,
nextDateLabel,
plugins,
+ headingLevel,
}: {
view: ScheduleView<Options>;
eventSource: ScheduleEventSource;
@@ -171,6 +174,7 @@ function ScheduleViewContent<Options extends ScheduleViewOptions>({
onNextDate: () => void;
nextDateLabel: string;
plugins: ReadonlyArray<SchedulePlugin>;
+ headingLevel: 2 | 3 | 4 | 5 | 6;
}) {
const Component = view.component;
const range = getRange(view, date);
@@ -195,6 +199,7 @@ function ScheduleViewContent<Options extends ScheduleViewOptions>({
nextDateLabel,
view,
plugins,
+ headingLevel,
}}>
<Component options={view.options} />
</ScheduleContext.Provider>
@@ -210,6 +215,7 @@ export function Schedule({
onChangeDate,
timezoneID: timezoneIDProp,
plugins = defaultSchedulePlugins,
+ headingLevel = 3,
xstyle,
className,
style,
@@ -285,6 +291,7 @@ export function Schedule({
onNextDate={onNextDate}
nextDateLabel={nextDateRange.label}
plugins={plugins}
+ headingLevel={headingLevel}
/>
}>
<ScheduleViewContent
@@ -300,6 +307,7 @@ export function Schedule({
onNextDate={onNextDate}
nextDateLabel={nextDateRange.label}
plugins={plugins}
+ headingLevel={headingLevel}
/>
</Suspense>
</div>
diff --git a/packages/lab/src/Schedule/TimeGridView.tsx b/packages/lab/src/Schedule/TimeGridView.tsx
index 3db0698663..a543b897a4 100644
--- a/packages/lab/src/Schedule/TimeGridView.tsx
+++ b/packages/lab/src/Schedule/TimeGridView.tsx
@@ -65,7 +65,7 @@ export function TimeGridView({
maxHour: number;
hourHeight: number;
}) {
- const {categories} = useScheduleContext();
+ const {categories, headingLevel} = useScheduleContext();
const normalizedMinHour = Math.max(0, Math.min(23, Math.floor(minHour)));
const normalizedMaxHour = Math.max(
normalizedMinHour + 1,
@@ -114,7 +114,7 @@ export function TimeGridView({
index === days.length - 1 && styles.timeGridHeaderCellLast,
)}>
<Heading
- level={4}
+ level={headingLevel}
color="secondary"
display="block"
xstyle={styles.timeGridHeaderHeading}>
diff --git a/packages/lab/src/Schedule/context.tsx b/packages/lab/src/Schedule/context.tsx
index 1e886498d0..d603906f38 100644
--- a/packages/lab/src/Schedule/context.tsx
+++ b/packages/lab/src/Schedule/context.tsx
@@ -34,6 +34,8 @@ export interface ScheduleContextValue {
nextDateLabel: string;
view: ScheduleViewBase;
plugins: ReadonlyArray<SchedulePlugin>;
+ /** Heading level used for sub-headings within the schedule (day labels, weekday headers). */
+ headingLevel: 2 | 3 | 4 | 5 | 6;
}
export const ScheduleContext = createContext<ScheduleContextValue | null>(