An open source design system that's fully customizable and agent ready
TypeScript
fix(templates): label the table-filter view-options panel by its selected tab (#7591)
Cindy Zhang4eaefd464907
diff --git a/.changeset/table-filter-view-tabpanel-label.md b/.changeset/table-filter-view-tabpanel-label.mdnew file mode 100644index 0000000000..a370ac72f3--- /dev/null+++ b/.changeset/table-filter-view-tabpanel-label.md@@ -0,0 +1,7 @@+---+'@astryxdesign/cli': patch+---++[fix] The `table-filter` page template's phone-width view-options panel is now labelled by its selected tab (`aria-labelledby`) instead of a fixed `aria-label`, so screen readers get the panel's name from the tab that controls it and the tab–panel relationship resolves in both directions.++@cixzhangdiff --git a/packages/cli/api/template/table-filter-view-tabs.test.mjs b/packages/cli/api/template/table-filter-view-tabs.test.mjsnew file mode 100644index 0000000000..e959e0caa1--- /dev/null+++ b/packages/cli/api/template/table-filter-view-tabs.test.mjs@@ -0,0 +1,45 @@+// Copyright (c) Meta Platforms, Inc. and affiliates.++/**+ * @file Regression coverage for the table-filter page's compact view-options tabs.+ * @input The shipped table-filter page template source.+ * @output Assertions that the shared tabpanel is labelled by its selected tab.+ * @position Template contract test for the tabs relationship in the narrow-view sheet.+ */++import fs from 'node:fs';+import path from 'node:path';+import {fileURLToPath} from 'node:url';+import {describe, expect, it} from 'vitest';++const sourcePath = path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ '../../assets/templates/pages/table-filter/page.tsx',+);+const source = fs.readFileSync(sourcePath, 'utf8');+const sheet = source.match(+ /const viewOptionsSheet = \(([\s\S]*?)\n {2}\);/,+)?.[1];+const tab = sheet?.match(/<Tab\b([\s\S]*?)\/>/)?.[1];+const panel = sheet?.match(/<VStack\b([^>]*?role="tabpanel"[^>]*?)>/)?.[1];++describe('table-filter view-options tabs', () => {+ it('finds the compact sheet, its tab and its panel', () => {+ expect(sheet).toBeDefined();+ expect(tab).toBeDefined();+ expect(panel).toBeDefined();+ });++ it('gives every tab an id derived from the panel id and its section', () => {+ expect(tab).toContain('id={`${viewPanelId}-tab-${section.key}`}');+ expect(tab).toContain('panelId={viewPanelId}');+ });++ it('labels the shared panel by the selected tab, not a fixed string', () => {+ expect(panel).toContain('id={viewPanelId}');+ expect(panel).toContain(+ 'aria-labelledby={`${viewPanelId}-tab-${viewSection}`}',+ );+ expect(panel).not.toContain('aria-label=');+ });+});diff --git a/packages/cli/assets/templates/pages/table-filter/page.tsx b/packages/cli/assets/templates/pages/table-filter/page.tsxindex 04c6bdf1c3..66d1485550 100644--- a/packages/cli/assets/templates/pages/table-filter/page.tsx+++ b/packages/cli/assets/templates/pages/table-filter/page.tsx@@ -4099,7 +4099,7 @@ export default function TableFilterTemplate() {restates the selected tab word for word, and the strip alreadymarks which one that is. On a phone that is a line of verticalspace spent saying it twice. The panel keeps the name for anyone- not seeing the strip, as its accessible label. */}+ not seeing the strip: its selected tab labels it. */}<TabListvalue={viewSection}onChange={value => setViewSection(value as ViewSection)}@@ -4109,6 +4109,7 @@ export default function TableFilterTemplate() {{VIEW_SECTIONS.map(section => (<Tabkey={section.key}+ id={`${viewPanelId}-tab-${section.key}`}value={section.key}label={section.label}icon={section.icon}@@ -4126,7 +4127,7 @@ export default function TableFilterTemplate() {gap={0}id={viewPanelId}role="tabpanel"- aria-label={activeSection?.title}+ aria-labelledby={`${viewPanelId}-tab-${viewSection}`}paddingBlockStart={3}>{viewPanelBody()}</VStack>