Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[material-ui] Fix negative input for CSS variables spacing array #45550

Merged
merged 4 commits into from
Mar 12, 2025

Conversation

siriwatknp
Copy link
Member

@siriwatknp siriwatknp commented Mar 12, 2025

closes #45500

Issue

Using negative spacing input does not work

const theme =createTheme({ cssVariables: true, spacing: [0, 4, 8] });

theme.spacing(-2) // ❌ does not work, it should produce `calc(-1 * var(--mui-spacing-2))`

Root cause

The logic does not handle the negative input, e.g. theme.spacing(-2) when the spacing input is an array and CSS variables enabled.

Please see the tests.

Improvements

This PR also include improvements for input value as 0 and 1 to save some bytes.

Before:

theme.spacing(0); // calc(0 * var(--mui-spacing))
theme.spacing(1); // calc(1 * var(--mui-spacing))

After:

theme.spacing(0); // 0
theme.spacing(1); // var(--mui-spacing)

Sorry, something went wrong.

@siriwatknp siriwatknp added package: system Specific to @mui/system package: material-ui Specific to @mui/material customization: theme Centered around the theming features labels Mar 12, 2025
@mui-bot
Copy link

mui-bot commented Mar 12, 2025

Netlify deploy preview

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

Bundle size report

Details of bundle changes (Toolpad)
Details of bundle changes

Generated by 🚫 dangerJS against 016a3a2

@siriwatknp siriwatknp enabled auto-merge (squash) March 12, 2025 07:29
@siriwatknp siriwatknp merged commit 5b77e0b into mui:master Mar 12, 2025
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
customization: theme Centered around the theming features package: material-ui Specific to @mui/material package: system Specific to @mui/system
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Negative spacing broken when using css variables and an array as spacing transformation
3 participants