Skip to content

Remove the role prop and RenderRowProps.isTreeGrid - #4268

Draft
nstepien wants to merge 2 commits into
mainfrom
breaking/remove-role-is-tree-grid
Draft

nstepien wants to merge 2 commits into
mainfrom
breaking/remove-role-is-tree-grid

Conversation

@nstepien

Copy link
Copy Markdown
Collaborator

DataGrid no longer accepts a role prop, and custom row renderers no longer receive isTreeGrid. DataGrid derived its tree-grid behavior from role === 'treegrid', so passing role="treegrid" turned on half of it (focusable rows, row positions) without any grouping, and any other value broke the ARIA structure; there was no valid value to pass. RenderRowProps.isTreeGrid leaked the same internal flag into the public row renderer props. Tree-grid behavior is now driven by an internal signal from TreeDataGrid.

Supersedes the isTreeGrid part of #3976; its renderSummaryRow addition is out of scope here.

Breaking change

- <DataGrid role="grid" … />
+ <DataGrid … />

  function renderRow(key, { isTreeGrid, ...props }: RenderRowProps<Row>) {
-   return <div role="row" tabIndex={isTreeGrid ? … : undefined} {...props} />;
+   return <div role="row" {...props} />;
  }

role is no longer a prop: DataGrid always has role="grid" and TreeDataGrid role="treegrid". Custom row renderers no longer receive isTreeGrid; in a TreeDataGrid, the active row's tabIndex and rdg-row-active class arrive as DOM props, so spread them onto the row element.

Changes

  • A module-private TreeGridContext (createContext(false), not exported from src/index.ts) replaces the role check. TreeDataGrid provides true around its DataGrid, and DataGrid reads it for isTreeGrid, renders role={isTreeGrid ? 'treegrid' : 'grid'}, and provides false to its own children, so a DataGrid rendered in a cell of a TreeDataGrid stays a plain grid. The false provider wraps the children inside DataGridRenderersContext, which re-indents that block; the diff reads better with whitespace hidden.
  • Row and SummaryRow no longer compute tabIndex or the rdg-row-active class. TreeDataGrid's renderRow wrapper passes them as DOM props (tabIndex, className) to the user's or the default renderRow, and Row already merges className and spreads the rest. DataGrid passes the same to SummaryRow through internal props when it's a tree grid. GroupedRow keeps its own logic.
  • Removed the dead rdg-row-active class from HeaderRow: navigation never puts the row position on the header row.
  • TreeDataGridProps no longer omits role, and the README drops the role prop, the TreeDataGrid "Unsupported Props" bullet, and isTreeGrid from RenderRowProps; the renderers.renderRow docs now say that a custom renderer rendering its own row element must spread the DOM props it receives.
  • Unlike Move row focus logic to <TreeGrid />, add renderSummaryRow #3976, this keeps the row focus styles in rdg.Row instead of moving them to a separate rowFocusable class, to keep the diff to the behavior change.

Verification

vp run ci passes. Added to test/browser/TreeDataGrid.test.tsx:

  • a DataGrid in a cell of a TreeDataGrid has role="grid", its rows and summary rows have no tabindex, and ← on its first cell keeps the cell active; this test fails when DataGrid forwards the context instead of resetting it;
  • a custom renderRow that renders its own row element and spreads the DOM props gets a focusable active row in a TreeDataGrid;
  • expectTypeOf checks that DataGridProps and TreeDataGridProps have no role and RenderRowProps has no isTreeGrid.

The existing tree grid row focus tests pass unchanged. I also type-checked a consumer of the built lib/index.d.ts with tsc --strict, with and without --exactOptionalPropertyTypes: role is rejected on DataGrid and TreeDataGrid, and isTreeGrid is absent from RenderRowProps.

🤖 Generated with Claude Code

`DataGrid` always renders `role="grid"` and `TreeDataGrid` `role="treegrid"`.
Tree-grid behavior is driven by a module-private `TreeGridContext` that
`TreeDataGrid` provides, and that `DataGrid` resets for its own children so a
grid nested in a cell isn't a tree grid. In a `TreeDataGrid`, the active row's
`tabIndex` and `rdg-row-active` class reach row renderers as DOM props.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov-commenter

codecov-commenter commented Oct 27, 2026 •

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.27%. Comparing base (5e7977b) to head (a6def88).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4268   +/-   ##
=======================================
  Coverage   99.27%   99.27%           
=======================================
  Files          44       45    +1     
  Lines        2204     2210    +6     
  Branches      965      972    +7     
=======================================
+ Hits         2188     2194    +6     
  Misses         16       16           
Files with missing lines Coverage Δ
src/DataGrid.tsx 99.45% <100.00%> (+<0.01%) ⬆️
src/HeaderRow.tsx 100.00% <100.00%> (ø)
src/Row.tsx 100.00% <ø> (ø)
src/SummaryRow.tsx 100.00% <100.00%> (ø)
src/TreeDataGrid.tsx 98.69% <100.00%> (+0.02%) ⬆️
src/TreeGridContext.ts 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants