An open source design system that's fully customizable and agent ready
TypeScript
fix(TableTree): rows carry no aria-expanded; the expander button does (#10538)
Cindy Zhang22b0599b431d
diff --git a/.changeset/table-tree-row-aria-expanded.md b/.changeset/table-tree-row-aria-expanded.mdnew file mode 100644index 0000000000..d91271028b--- /dev/null+++ b/.changeset/table-tree-row-aria-expanded.md@@ -0,0 +1,7 @@+---+'@astryxdesign/core': patch+---++[fix] TableTree rows no longer carry `aria-expanded`, which is valid on a row only in a treegrid. Each row's expand and collapse button still exposes its expanded state, and rows keep `aria-level` for their depth.++@cixzhangdiff --git a/docs/specs/components/Table/plugins/tree/useTableTreeData.spec.md b/docs/specs/components/Table/plugins/tree/useTableTreeData.spec.mdindex 5310904cb3..602c68e12c 100644--- a/docs/specs/components/Table/plugins/tree/useTableTreeData.spec.md+++ b/docs/specs/components/Table/plugins/tree/useTableTreeData.spec.md@@ -53,6 +53,7 @@ A tree expansion button identifies the row it controls at every depth. This reco- Released default preserved: yes; an omitted callback keeps generic localized expansion names.- Compatibility class: optional additive API with no tree-data, row-key, expansion-state or interaction change.- Migration decision: DEC-1. Consumer usage belongs in `useTableTreeData.doc.mjs`.+- Known validation exception: body rows carry no `aria-expanded` (the expansion button carries it, AR1), but they keep `aria-level` outside a treegrid. Chromium exposes it as the row's depth, leaves included. Accessibility checkers report it, and it goes away when tree tables gain treegrid semantics.## Ownership boundarydiff --git a/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx b/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsxindex aa8f3bdc44..0673b609b8 100644--- a/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx+++ b/packages/core/src/Table/plugins/tree/useTableTreeData.test.tsx@@ -482,16 +482,20 @@ describe('useTableTreeData — row ARIA', () => {expect(getRowByText('README.md')).toHaveAttribute('aria-level', '1');});- it('sets aria-expanded on expandable rows and omits it on leaves', () => {+ it('body rows carry no aria-expanded; the expander button does', () => {render(<TreeTable defaultExpandedIds={['src']} />);- expect(getRowByText('src')).toHaveAttribute('aria-expanded', 'true');- expect(getRowByText('components')).toHaveAttribute(- 'aria-expanded',- 'false',- );- expect(getRowByText('utils.ts')).not.toHaveAttribute('aria-expanded');- expect(getRowByText('README.md')).not.toHaveAttribute('aria-expanded');+ for (const row of getBodyRows()) {+ expect(row).not.toHaveAttribute('aria-expanded');+ }+ expect(+ within(getRowByText('src')).getByRole('button', {name: 'Collapse row'}),+ ).toHaveAttribute('aria-expanded', 'true');+ expect(+ within(getRowByText('components')).getByRole('button', {+ name: 'Expand row',+ }),+ ).toHaveAttribute('aria-expanded', 'false');});});@@ -714,8 +718,8 @@ describe('useTableTreeData — treeColumnKey', () => {});it('falls back to the first column when the configured column is absent', () => {- // e.g. columnSettings hid the configured tree column — the expander- // must not vanish while rows still announce aria-expanded.+ // e.g. columnSettings hid the configured tree column — the expander,+ // which carries the row's expansion state, must not vanish.render(<TreeTable treeColumnKey="not-a-column" />);const srcRow = getRowByText('src');diff --git a/packages/core/src/Table/plugins/tree/useTableTreeData.tsx b/packages/core/src/Table/plugins/tree/useTableTreeData.tsxindex a7e5d81d56..7e95121c2f 100644--- a/packages/core/src/Table/plugins/tree/useTableTreeData.tsx+++ b/packages/core/src/Table/plugins/tree/useTableTreeData.tsx@@ -19,10 +19,9 @@** Expansion state flows through an external store (TreeStore) so each* row's expander subscribes independently — a toggle re-renders only the- * affected cells, not the whole body. Row ARIA (aria-level,- * aria-expanded) is applied imperatively via a ref callback on each- * <tr>, exactly like selection's row styling; each subscription- * self-cleans when the row disconnects.+ * affected cells, not the whole body. A ref callback on each <tr> sets its+ * aria-level, as selection's row styling does. Each subscription ends when+ * its row disconnects.** When `hasExpandableRows` is false (flat data), every transform is a* pass-through: adopting the plugin ahead of hierarchical data is a@@ -232,21 +231,18 @@ function useRowSnapshot<T extends Record<string, unknown>>(// Row ARIA (imperative, mirrors selection's row styling)// =============================================================================+// aria-expanded is valid on a row only in a treegrid, so it stays on the+// expander button. aria-level is also treegrid-only, but Chromium exposes it+// as the row's depth, so rows keep it.function applyRowTreeAria(el: HTMLTableRowElement,meta: TableTreeRowMeta | undefined,): void {if (!meta) {el.removeAttribute('aria-level');- el.removeAttribute('aria-expanded');return;}el.setAttribute('aria-level', String(meta.level + 1));- if (meta.hasChildren) {- el.setAttribute('aria-expanded', String(meta.isExpanded));- } else {- el.removeAttribute('aria-expanded');- }}// =============================================================================diff --git a/packages/core/src/Table/useTableTreeData.doc.mjs b/packages/core/src/Table/useTableTreeData.doc.mjsindex 98493f2f19..04faa24184 100644--- a/packages/core/src/Table/useTableTreeData.doc.mjs+++ b/packages/core/src/Table/useTableTreeData.doc.mjs@@ -7,7 +7,7 @@ export const docs = {subComponentOf: 'Table',displayName: 'useTableTreeData',description:- 'Headless tree plugin for Table: renders nested rows with per-level indentation and expand/collapse chevrons in the tree column (the first column by default), and reflects hierarchy on body rows via aria-level and aria-expanded. Composable with the other Table plugins: the canonical plugin order places tree before selection, so the checkbox column lands left of the indented tree column. Feed it the treeConfig from useTableTreeState, or construct the config directly for server-driven or pre-flattened trees. When no row is expandable (flat data), every transform is a pass-through and the table renders identically to one without the plugin. Known limitation: the tree column wraps its cell content, so textOverflow="truncate" tooltips do not apply within the tree column.',+ 'Headless tree plugin for Table: renders nested rows with per-level indentation and expand/collapse chevrons in the tree column (the first column by default), and reflects hierarchy with aria-level on body rows and aria-expanded on each expand/collapse button. Composable with the other Table plugins: the canonical plugin order places tree before selection, so the checkbox column lands left of the indented tree column. Feed it the treeConfig from useTableTreeState, or construct the config directly for server-driven or pre-flattened trees. When no row is expandable (flat data), every transform is a pass-through and the table renders identically to one without the plugin. Known limitation: the tree column wraps its cell content, so textOverflow="truncate" tooltips do not apply within the tree column.',props: [{name: 'getRowMeta',@@ -101,7 +101,7 @@ export const docsDense = {name: 'useTableTreeData',displayName: 'useTableTreeData',description:- 'Headless tree plugin: indent + expander chevron on the tree column (first column by default), aria-level/aria-expanded on body rows. Canonical plugin order puts tree before selection (checkbox column lands left of tree column). Consume treeConfig from useTableTreeState, or construct directly for server-driven trees. hasExpandableRows=false => full no-op (flat-data migration).',+ 'Headless tree plugin: indent + expander chevron on the tree column (first column by default), aria-level on body rows, aria-expanded on each expander button. Canonical plugin order puts tree before selection (checkbox column lands left of tree column). Consume treeConfig from useTableTreeState, or construct directly for server-driven trees. hasExpandableRows=false => full no-op (flat-data migration).',propDescriptions: {getRowMeta:'structural meta per visible row: {id, level (0-based), hasChildren, isExpanded}',