Repository navigation
DataTable: Add controllable row group expansion - #8533
rickyzhangca wants to merge 10 commits into
Conversation
🦋 Changeset detectedLatest commit: cc1abbf The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
|
🤖 Lint issues have been automatically fixed and committed to this PR. |
|
🤖 Lint issues have been automatically fixed and committed to this PR. |
There was a problem hiding this comment.
🟡 Changes recommended
Callback refs break mixed-state selection, and manual screen-reader validation remains outstanding.
1 open finding
What changed in this PR
Adds opt-in group expansion to experimental DataTable and Table.Group, building on current-page row selection.
Changes:
- Adds controlled and uncontrolled expansion with stable group IDs.
- Keeps collapsed rows mounted and selectable, with focus recovery.
- Adds documentation, examples, and regression coverage.
| File | Description |
|---|---|
| packages/react/src/experimental/index.ts | Exports selection types. |
| packages/react/src/DataTable/useTable.ts | Manages selection and expansion state. |
| packages/react/src/DataTable/TableGroup.tsx | Adds disclosure controls and focus recovery. |
| packages/react/src/DataTable/Table.tsx | Adds composable selection controls. |
| packages/react/src/DataTable/Table.module.css | Styles disclosures and hidden groups. |
| packages/react/src/DataTable/Table.features.stories.tsx | Demonstrates presentational APIs. |
| packages/react/src/DataTable/row.ts | Defines shared row ID type. |
| packages/react/src/DataTable/index.ts | Exposes selection components and types. |
| packages/react/src/DataTable/DataTable.types.test.tsx | Checks public API types. |
| packages/react/src/DataTable/DataTable.tsx | Integrates selection and expansion. |
| packages/react/src/DataTable/DataTable.features.stories.tsx | Adds interactive examples. |
| packages/react/src/DataTable/DataTable.docs.json | Documents new APIs. |
| packages/react/src/DataTable/DataTable.accessibility.md | Explains accessibility contracts. |
| packages/react/src/DataTable/__tests__/DataTableSelection.test.tsx | Tests selection behavior. |
| packages/react/src/DataTable/__tests__/DataTableGrouping.test.tsx | Updates typed group-key expectations. |
| packages/react/src/DataTable/__tests__/DataTableExpansion.test.tsx | Tests expansion, focus, and hydration. |
| packages/react/src/__tests__/__snapshots__/exports.test.ts.snap | Records added exports. |
| e2e/components/Table.test.ts | Covers composed selection interactions. |
| e2e/components/DataTable.test.ts | Covers expansion and selection scenarios. |
| .changeset/selectable-data-table-rows.md | Records selection release addition. |
| .changeset/datatable-group-expansion.md | Records expansion release addition. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Recover focus at commit time without layout effects, preserve disclosure target size under long labels, and tighten expansion documentation and regression coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Center the 24px disclosure target over the checkbox slot and derive text spacing from cell density. Cover alignment in both directions and expansion states. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Replace the arbitrary Tab loop with explicit focus destinations and retain dedicated state, selection, hydration, sizing, and alignment coverage. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
8bf43cc to
a0d03f4
Compare
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Restore unrelated AvatarStack image churn from the snapshot workflow. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Integration test results from github/github-ui PR:
All checks passed! |

Closes https://github.com/github/primer/issues/6721
Adds opt-in group expansion to
DataTableandTable.Group. Builds on the row selection merged in #8415 and targetsmain; bulk actions remains an independent sibling PR.Collapsing only changes visibility. Members stay mounted and remain in the selection model, so current-page select-all includes collapsed selectable rows. A controlled collapse restores focus to the disclosure only when it hides the focused member.
CleanShot.2026-10-14.at.5.09.31.PM.mp4
Changelog
New
DataTable:collapsibleGroups,expandedGroups,defaultExpandedGroups,onExpandedGroupsChange({expandedGroups}). Expansion sets use stable string/number group IDs.Table.Group:collapsible,expanded,defaultExpanded,onExpandedChange({expanded}).Changed
Group keys distinguish string and numeric IDs. Non-collapsible groups remain expanded. Uncontrolled expansion defaults to the groups in the initial data; new IDs start collapsed, and stored IDs survive data replacement.
Removed
None.
Rollout strategy
Opt-in experimental API addition. Review/merge bulk actions before expansion; neither follow-up changes the other's implementation.
Testing & Reviewing
VITEST_FAIL_ON_CONSOLE=true npm test -- --run: passed, 2744 tests with React 18.3.1, including browser-rendered SSR and hydration without warning suppression.VITEST_FAIL_ON_CONSOLE=true npm test -- --run packages/react/src/DataTable/__tests__: passed, 206 tests covering state, selection compatibility, focus, hydration, and disclosure size with long labels. Alignment assertions cover all three densities, LTR/RTL, and expanded/collapsed states.npm run build,npm run type-check: passed.npm run lint,npm run lint:css,npm run format:diff,npm run test:classname-coverage: passed.npx markdownlint-cli2 packages/react/src/DataTable/DataTable.accessibility.md: passed.npm run format,npm run lint:fix: passed before committing.STORYBOOK_URL=http://localhost:6008 npx playwright test e2e/components/DataTable.test.ts --grep 'group expansion hides' --workers=1: passed; verifies keyboard activation, controlled-collapse focus recovery, hidden Tab order, selection compatibility, and axe.Manual review still needed: verify NVDA/JAWS/VoiceOver disclosure name, count, expanded state, and table navigation across collapsed groups. Automated checks do not replace assistive-technology review. Count descriptions currently use English. The implementation uses Primer's existing button/state primitives, not
@github-ui/disclosure.