Skip to content

[data-grid] Fix DataGrid cell text vertical alignment#21731

Draft
aman44444 wants to merge 3 commits intomui:masterfrom
aman44444:datagrid-lineheight-alignment
Draft

[data-grid] Fix DataGrid cell text vertical alignment#21731
aman44444 wants to merge 3 commits intomui:masterfrom
aman44444:datagrid-lineheight-alignment

Conversation

@aman44444
Copy link

@aman44444 aman44444 commented Mar 13, 2026

Fixes mui/material-ui#47118

Root cause

Cells currently rely on line-height to vertically center text:

line-height: calc(var(--height) - 1px)

This couples vertical alignment to typography. When line-height changes through theme or font settings, text alignment becomes inconsistent and the selection highlight fills the entire cell height instead of the text line.

Fix

Replace line-height centering with flex alignment:

display: flex;
align-items: center;
line-height: inherit;

Since text-overflow: ellipsis breaks when the cell becomes a flex container, direct string content is wrapped in a span and flex children are allowed to shrink so truncation works correctly.

Tested

Verified on the docs site with:

@aman44444 aman44444 marked this pull request as draft March 13, 2026 03:12
@mui-bot
Copy link

mui-bot commented Mar 13, 2026

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

Bundle size report

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+211B(+0.05%) 🔺+31B(+0.03%)
@mui/x-data-grid-pro 🔺+211B(+0.04%) 🔺+55B(+0.04%)
@mui/x-data-grid-premium 🔺+211B(+0.03%) 🔺+57B(+0.03%)
@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 092ab11

@aman44444 aman44444 marked this pull request as ready for review March 13, 2026 03:32
@aman44444 aman44444 marked this pull request as draft March 13, 2026 03:42
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.

[data grid] Improve font usage

2 participants