DataTable: Add config-driven row groups - #8386
Conversation
🦋 Changeset detectedLatest commit: 8f84e39 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 |
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
There’s a correctness issue in the row-group runtime type guard (groups can be misclassified if they include an id field), plus a small e2e gate that should check aat truthiness rather than key presence.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Review tier: Lite
Findings: 1
New issues introduced by this change (2)
| Severity | Finding |
|---|---|
packages/react/src/DataTable/useTable.ts — isDataTableRowGroup requires the group object to not have an id property (`!Reflect.has(item,… |
|
e2e/components/DataTable.test.ts — The AAT gate currently uses if ('aat' in story), which will run the axe test for any story object… |
What changed in this PR
Adds a config-driven row-grouping model to the experimental DataTable API by allowing data to be either a flat row array or a grouped row-array shape, rendering groups via the presentational Table.Group primitive and improving header associations for accessibility.
Changes:
- Introduces
DataTableRowGroup/DataTableDatatypes and exports them from the experimental entrypoint. - Updates
useTable+DataTablerendering to support grouped data while sorting within each group and preserving group order. - Adds unit, type-level, and e2e coverage for grouped tables and header associations (including AAT for the grouped story).
| File | Description |
|---|---|
| packages/react/src/experimental/index.ts | Exports new DataTableData and DataTableRowGroup types from the experimental entrypoint. |
| packages/react/src/DataTable/useTable.ts | Accepts grouped data, validates shape, and applies per-group sorting while preserving group order. |
| packages/react/src/DataTable/row.ts | Defines DataTableRowGroup and DataTableData types. |
| packages/react/src/DataTable/index.ts | Re-exports new grouping-related types. |
| packages/react/src/DataTable/DataTable.types.test.tsx | Adds type-level tests to ensure grouped props and inference work. |
| packages/react/src/DataTable/DataTable.tsx | Renders TableGroup when grouped; adds deterministic header IDs and headers associations. |
| packages/react/src/DataTable/DataTable.stories.tsx | Wraps DataTable for Storybook component typing. |
| packages/react/src/DataTable/DataTable.features.stories.tsx | Updates With Groups to use config-driven groups; keeps composed example as WithComposedGroups. |
| packages/react/src/DataTable/DataTable.docs.json | Documents the new data union shape and adds the composed-groups story to docs. |
| packages/react/src/DataTable/__tests__/DataTableGrouping.test.tsx | Adds focused grouping behavior and accessibility association tests (incl. SSR ID uniqueness). |
| packages/react/src/DataTable/__tests__/DataTable.test.tsx | Adds regression coverage for headers associations in ungrouped tables. |
| packages/react/src/__tests__/__snapshots__/exports.test.ts.snap | Updates snapshot for new experimental type exports. |
| e2e/components/DataTable.test.ts | Enables axe AAT for the grouped DataTable story across themes. |
| .changeset/grouped-data-table.md | Minor changeset for the new config-driven grouping capability + new exports. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
🤖 Lint issues have been automatically fixed and committed to this PR. |
Allow DataTable consumers to supply grouped data while preserving group order during sorting. Render groups through Table.Group with automatic header associations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep the exported props type compatible with the component while preserving inline grouped-data inference. Include row header IDs in explicit cell header associations. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Keep explicit row-type generics while supporting props objects and inline grouped-data inference. Arrange table helpers so the React Compiler can process grouped sorting. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Recognize row groups that include additional properties and gate accessibility tests on the configured boolean value. Exclude the grouping behavior suite from component className coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Limit explicit header associations to grouped tables and cover sortable headers, empty groups, and SSR hydration. Document ownership across the presentational and config APIs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
f796e1b to
8f84e39
Compare


Refs github/primer#6720
Follows #8372, which introduced the presentational
Table.GroupAPI, and includes the sortable-header accessibility behavior from #8371.Array<Data>Array<Data> | Array<DataTableRowGroup<Data>><DataTable data={rows} columns={columns} /><DataTable data={groups} columns={columns} />{type: 'row-group', groupId, label, rows, 'aria-label'?}Table.Groupremains available as the presentational escape hatchGrouped data example
Changelog
New
DataTablethrough groupeddataentries.DataTableRowGroupandDataTableDatatypes from the experimental entrypoint.Changed
Removed
Rollout strategy
Testing & Reviewing
npm run buildnpm test(157 files, 2,666 passed, 2 skipped, 10 todo)npm run type-checknpm run lintnpm run lint:cssnpm run lint:react-compiler --workspace=@primer/react -- --no-cachenpm run build:components.json --workspace=@primer/reactnpm run test:classname-coveragenpm run format:diffheadersreferences remain valid after sorting.Review the
With GroupsDataTable feature story for the config-driven API andWith Sortable Groupsfor the sortable accessibility contract.With Composed Groupsremains available as the lower-levelTable.Groupexample introduced in #8372.