Skip to content

[data grid] Incorrect handling of numeric font size in formatFont #19510

@afn

Description

@afn

Steps to reproduce

Steps:

  1. Open this link to live example: https://codesandbox.io/p/sandbox/inspiring-sky-4v6vd2

Note the fontSize: 14 in the definition of typography.body2. Changing it to fontSize: '14px' corrects the incorrect behavior.

Current behavior

If fontSize is a number, the --DataGrid-t-typography-font-body variable (and therefore the font attribute) is incorrectly set to 400 14 / 1.43 "Roboto", "Helvetica", "Arial", sans-serif

Expected behavior

The font attribute should be set to 400 14px / 1.43 "Roboto", "Helvetica", "Arial", sans-serif

Context

The bug is in the formatFont function. Instead of interpolating font.fontSize as-is, it should append px if the value is a number, similar to what is done in getRadius.

Your environment

npx @mui/envinfo
  System:
    OS: macOS 15.5
  Binaries:
    Node: 20.19.0 - ~/.nvm/versions/node/v20.19.0/bin/node
    npm: 10.8.2 - ~/.nvm/versions/node/v20.19.0/bin/npm
    pnpm: Not Found
  Browsers:
    Chrome: 140.0.7339.133
    Edge: Not Found
    Safari: 18.5

Search keywords: formatFont px font size fontSize

Order ID: 117263

Metadata

Metadata

Assignees

No one assigned

    Labels

    scope: data gridChanges related to the data grid.support: premium standardSupport request from a Premium standard plan user. https://mui.com/legal/technical-support-sla.type: regressionA bug, but worse, it used to behave as expected.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions