Skip to content

[material-ui][Badge] Use inline CSS variables for anchorOrigin/overlap positioning#48549

Merged
siriwatknp merged 6 commits into
mui:masterfrom
siriwatknp:worktree-badge-inline-css-vars
May 20, 2026
Merged

[material-ui][Badge] Use inline CSS variables for anchorOrigin/overlap positioning#48549
siriwatknp merged 6 commits into
mui:masterfrom
siriwatknp:worktree-badge-inline-css-vars

Conversation

@siriwatknp

@siriwatknp siriwatknp commented May 20, 2026

Copy link
Copy Markdown
Member

Follow-up to #47742.

Instead of computing positioning via a style: ({ ownerState }) => {...} callback in the styled variants array, this PR:

  • Replaces the callback with a plain object that references CSS variables.
  • Moves the anchorOrigin × overlap conditional logic onto the badge slot's inline style, which sets those CSS variables.

Why

  • Keeps the styled variants purely declarative (plain objects only).
  • Pushes per-render conditional logic out of the styled engine — cheaper at render time and easier for static extraction tools.

Variables

Three CSS variables drive positioning, leveraging existing CSS shorthand:

  • --Badge-translatetranslateX, translateY (comma-separated, for the translate() function)
  • --Badge-insettop right bottom left (space-separated, for the inset shorthand)
  • --Badge-originX Y (space-separated, for transform-origin)

Follows the same "inline-style sets a --ComponentName-* variable, styled CSS consumes it" pattern already used by:

  • AvatarGroup--AvatarGroup-spacing (from the spacing prop)
  • Typography--Typography-textAlign (from the align prop)
  • TabScrollButton--TabScrollButton-svgRotate (from RTL + orientation)

Behavior

No visible change. Same eight outcomes (top/bottom × left/right × rectangular/circular) produce the same CSS output as before #47742.

@code-infra-dashboard

code-infra-dashboard Bot commented May 20, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-48549--material-ui.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/material ▼-15B(0.00%) 🔺+22B(+0.01%)
@mui/lab 0B(0.00%) 0B(0.00%)
@mui/private-theming 0B(0.00%) 0B(0.00%)
@mui/system 0B(0.00%) 0B(0.00%)
@mui/utils 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

Comment thread packages/mui-material/src/Badge/Badge.js
Comment thread packages/mui-material/src/Badge/Badge.js
@siriwatknp siriwatknp marked this pull request as ready for review May 20, 2026 11:12
@siriwatknp siriwatknp added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: badge Changes related to the badge. package: material-ui Specific to Material UI. needs cherry-pick The PR should be cherry-picked to master after merge. v7.x labels May 20, 2026
@siriwatknp siriwatknp merged commit 7a630f0 into mui:master May 20, 2026
23 checks passed
@github-actions

Copy link
Copy Markdown

Cherry-pick PRs will be created targeting branches: v7.x

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs cherry-pick The PR should be cherry-picked to master after merge. package: material-ui Specific to Material UI. scope: badge Changes related to the badge. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. v7.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants