fix: restore icon centering after MUI v9 upgrade - #12440
Merged
Merged
Conversation
MUI v5's Box converted the system prop fontSize={0} to font-size: 0,
zeroing the strut so the svg child filled the icon span. Since the v9
upgrade (52d5bce) Box only styles through sx, so the prop was passed
through as a dead font-size="0" DOM attribute and every s:true icon
(svg child path) drifted down a few px inside text-sized containers
(e.g. MaskBlue size={16} in the ProfileCard avatar badge).
Move fontSize: 0 into the sx base style (restoring v5 semantics), add
lineHeight: 0 to guard against host pages inheriting an absolute
line-height, and drop the dead prop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
s: true, svg rendered as a child of the icon span — e.g.Icons.MaskBlue) drifted a few px down inside text-sized containers after the MUI v9 upgrade.__createIconpassedfontSize: 0as a system prop toBox. MUI v5 converted system props to CSS (font-size: 0), zeroing the strut so the svg filled the span. Since 52d5bce (5.15.20 → 9.2.0),Boxonly styles throughsx— the prop leaked to the DOM as a uselessfont-size="0"attribute, the strut came back, and the inline svg got pushed below the baseline. Smallersizemade it more visible (e.g.MaskBlue size={16}in the ProfileCard avatar badge sitting in an IconButton withfont-size: 24px).packages/icons/utils/internal.js:fontSize: 0into thesxbase style (restores v5 semantics under v9);lineHeight: 0to guard against host pages inheriting an absoluteline-height;fontSizeprop).Impact
__createIconis the single factory for all generated icons, so this fixes everys: trueicon at once. Background-image variants (no child element) are unaffected byfontSize/lineHeight. TheSvgIcon-basedcreateIcon()inutils/index.jsis unaffected.Verification
font-size: 0px; line-height: 0px; nofont-sizeDOM attribute remains;MaskBlue size={16}in the avatar badge: svg center vs button center delta = 0px (was offset before);MaskBlue size={24}dialog header icon likewise centered;React does not recognize the "fontSize" propwarning.