Skip to content

[data grid] Fix selected row background with cssVariables.nativeColor - #24215

Merged
LukasTy merged 2 commits into
mui:v8.xfrom
insanrizky:fix-grid-selected-native-color
Dec 1, 2026
Merged

LukasTy merged 2 commits into
mui:v8.xfrom
insanrizky:fix-grid-selected-native-color

Conversation

@insanrizky

@insanrizky insanrizky commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #24189 on v8.x.

With cssVariables: { nativeColor: true }, Material UI does not emit the *Channel tokens, so theme.vars.palette.primary.mainChannel is undefined and the grid's --DataGrid-t-color-interactive-selected becomes rgb(undefined). The selected row then has no background.

This uses (t.vars || t).palette.primary.main for the selection color, the same value master already uses (from #21892), without the minimum core version bump. The variable is only consumed inside color-mix(), so a var(--mui-palette-primary-main) value works with and without nativeColor.

How tested: rendered useMaterialCSSVariables() from @mui/x-data-grid@8.29.5 with createTheme({ cssVariables: { nativeColor } }) (with CSS.supports stubbed so the color-mix branch runs):

nativeColor before after
false rgb(var(--mui-palette-primary-mainChannel)) var(--mui-palette-primary-main)
true rgb(undefined) var(--mui-palette-primary-main)

Prettier (3.7.4 with the repo config) passes on the changed file.

Note: the backdrop color (background.defaultChannel) and the row drag-and-drop overlay (primary.mainChannel) use channel tokens too; happy to follow up if you want those covered as well.
☝️ Done.

AI-assisted and reviewed by me.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mui-bot

mui-bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Deploy preview: https://deploy-preview-24215--material-ui-x.netlify.app/

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid ▼-57B(-0.01%) ▼-35B(-0.03%)
@mui/x-data-grid-pro ▼-57B(-0.01%) ▼-11B(-0.01%)
@mui/x-data-grid-premium ▼-57B(-0.01%) ▼-3B(0.00%)
@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%)

Details of bundle changes

Generated by 🚫 dangerJS against 86ad25c

@zannager zannager added the scope: data grid Changes related to the data grid. label Nov 17, 2026
@LukasTy LukasTy added the type: bug It doesn't behave as expected. label Nov 30, 2026

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution. 🙏

Claude Opus findings

The fix is correct. It is the same line as master (from #21892) and does not need the core version bump. I checked it with @mui/material@7.3.11 in Chromium: with nativeColor, the selected row background changes from transparent to the mixed primary color.

  • The same bug is in two more places. With nativeColor, the backdrop in variables.ts resolves to rgba(undefined / var(--mui-palette-action-disabledOpacity, 0.38)), and the inside drop target in GridRowDragAndDropOverlay.tsx resolves to rgba(undefined / 0.1). Both compute to transparent. Thus the loading overlay does not dim the rows, and the tree data "inside" drop target has no highlight. I suggest that you fix both in this PR. variables.ts already has a setOpacity() helper for this, and the focus color uses it:

    const backgroundBackdrop = t.vars
      ? setOpacity(t.vars.palette.background.default, t.vars.palette.action.disabledOpacity)
      : alpha(t.palette.background.default, t.palette.action.disabledOpacity);

    For the drag overlay, use the same rgba(from ${theme.vars.palette.primary.main} r g b / 0.1) form.

…tiveColor`

With `nativeColor`, Material UI does not generate the `*Channel` tokens,
so the loading backdrop and the "inside" drop target resolved to
`rgba(undefined / ...)`. Build them from the color tokens instead.

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

Copy link
Copy Markdown
Contributor Author

@LukasTy Thanks! Applied both suggestions: the backdrop now uses setOpacity() and the inside drop target uses rgba(from … r g b / 0.1). With nativeColor, both now compute to the expected colors in Chromium instead of transparent.

@LukasTy LukasTy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for addressing this. 🙏

While testing, I found that Material UI v7 doesn't have the fix for TableCell color, created a backport PR to address it (mui/material-ui#49958).

@LukasTy
LukasTy merged commit 54fb311 into mui:v8.x Dec 1, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: data grid Changes related to the data grid. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants