Repository navigation
[data grid] Fix selected row background with cssVariables.nativeColor - #24215
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Deploy preview: https://deploy-preview-24215--material-ui-x.netlify.app/ Bundle size report
|
LukasTy
left a comment
There was a problem hiding this comment.
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 invariables.tsresolves torgba(undefined / var(--mui-palette-action-disabledOpacity, 0.38)), and theinsidedrop target inGridRowDragAndDropOverlay.tsxresolves torgba(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.tsalready has asetOpacity()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>
|
@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
left a comment
There was a problem hiding this comment.
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).
Fixes #24189 on v8.x.
With
cssVariables: { nativeColor: true }, Material UI does not emit the*Channeltokens, sotheme.vars.palette.primary.mainChannelisundefinedand the grid's--DataGrid-t-color-interactive-selectedbecomesrgb(undefined). The selected row then has no background.This uses
(t.vars || t).palette.primary.mainfor the selection color, the same valuemasteralready uses (from #21892), without the minimum core version bump. The variable is only consumed insidecolor-mix(), so avar(--mui-palette-primary-main)value works with and withoutnativeColor.How tested: rendered
useMaterialCSSVariables()from@mui/x-data-grid@8.29.5withcreateTheme({ cssVariables: { nativeColor } })(withCSS.supportsstubbed so the color-mix branch runs):nativeColorfalsergb(var(--mui-palette-primary-mainChannel))var(--mui-palette-primary-main)truergb(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.