Skip to content

[DataGrid] Export ToolbarRoot - #23322

Draft
JCQuintas wants to merge 2 commits into
mui:masterfrom
JCQuintas:export-toolbar-root
Draft

[DataGrid] Export ToolbarRoot#23322
JCQuintas wants to merge 2 commits into
mui:masterfrom
JCQuintas:export-toolbar-root

Conversation

@JCQuintas

Copy link
Copy Markdown
Member

Closes #23314

ToolbarRoot, the styled <div /> rendered by <Toolbar />, was module-private, so there was no way to reuse the toolbar styles elsewhere without copy-pasting them and keeping them in sync by hand.

Export

ToolbarRoot is now exported from @mui/x-data-grid (and, through the usual re-export, from the Pro and Premium packages).

Making it usable outside of the Data Grid

Exporting it alone was not enough. The styles reference the --DataGrid-t-* CSS variables, which are only defined on the Data Grid root element, so a ToolbarRoot rendered anywhere else lost its padding, gap and bottom border.

The two variables it uses are now declared with a fallback resolved from the theme:

const spacingUnit = `var(${vars.keys.spacingUnit}, ${getSpacingUnit(theme)})`;
const borderColor = `var(${vars.keys.colors.border.base}, ${getBorderColor(theme)})`;

Inside a Data Grid the variables are defined and win, so nothing changes. Outside, the theme values are used and the element matches the real toolbar.

getBorderColor was already there and is now exported; getSpacingUnit is the expression that was already inline in transformTheme, extracted so both call sites stay in sync.

Docs

New "Reusing the toolbar styles" section on the Toolbar page, with a demo using <ToolbarRoot /> as the header of a card containing a Data Grid.

Notes for reviewers

  • Toolbar.tsx now imports from material/variables. It is the first component in the generic layer to depend on the Material adapter, so a standalone ToolbarRoot falls back to the Material theme rather than to a custom useCSSVariables adapter. Happy to move the indirection if you would rather keep that boundary clean.
  • ToolbarRoot deliberately does not provide the toolbar context, so ToolbarButton and the other subcomponents cannot be used inside it. This is documented.

Allows reusing the toolbar styles outside of the toolbar, for example in the
header of a drawer displayed alongside the Data Grid.

Closes mui#23314
The toolbar styles referenced the Data Grid CSS variables directly, which are
only defined on the Data Grid root element. Rendered anywhere else, ToolbarRoot
lost its padding, gap and bottom border.

Declare those references with a fallback resolved from the theme, so the
component can be used standalone while still preferring the variables when they
are defined.

Replaces the drawer demo with a simpler one that no longer needs
GridPortalWrapper.
@JCQuintas JCQuintas self-assigned this Aug 11, 2026
@JCQuintas JCQuintas added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: data grid Changes related to the data grid. docs Improvements or additions to the documentation. labels Aug 11, 2026
@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+152B(+0.04%) 🔺+60B(+0.05%)
@mui/x-data-grid-pro 🔺+152B(+0.03%) ▼-28B(-0.02%)
@mui/x-data-grid-premium 🔺+152B(+0.02%) 🔺+16B(+0.01%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-scheduler 0B(0.00%) 0B(0.00%)
@mui/x-scheduler-premium 0B(0.00%) 0B(0.00%)
@mui/x-chat 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

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

Labels

docs Improvements or additions to the documentation. scope: data grid Changes related to the data grid. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export ToolbarRoot to enable style reuse

1 participant