[material-ui] Inconsistent spacing units between components under default styling
@siriwatknp is already working on this.
Since Feb 8, 2024.
- Dominant language
- JavaScript
- Stars
- 99.1k
- Forks
- 32.5k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 106
Description
Steps to reproduce
Link to live example: https://codesandbox.io/p/sandbox/sad-forest-g88786?file=%2Fsrc%2Findex.tsx%3A35%2C3
You'll see there is red inner content surrounded by green outer content - the hope is that this illustrates where padding is used.
Current behavior
Spacing units is inconsistent between different components' default styles. This issue becomes very apparent when adding a custom spacing function to the theme.
When specifying space in the sx of any component the behavior is consistent and predictable
padding: 16will get converted topadding: 1.6rempadding: "16px"stayspadding: "16px"padding: theme.spacing(20, 40)becomespadding: 2rem 4rem
etc
Unfortunately with the way default styles are defined on out of the box components, this custom spacing function completely breaks consistency on some base styles.
For example:
- Button's base padding is defined as
padding: '6px 16px'- which stays the same (padding: '6px 16px') - CardContent's base padding is
padding: 16- which gets converted topadding: 1.6rem - AccordionSummary's base padding is
padding: theme.spacing(0, 2)- which gets converted topadding: 0 0.2rem
Button and CardContent's padding ends up matching what the original intent was and renders appropriately.
AccordionSummary's padding ends up being completely wrong.
Expected behavior
My hope is that in the future there is consistency between component's base styles' use of units on spacing. It seems like unit-less spacing in these default styles would be preferred, so that in the end the spacing function is used and devs have more control over what that actually means. This seems like something that should be enforced on the project as a whole.
Context
Above is an example (and mirrors my project's production environment) where we convert all spacing units to rem, and base it on the fact the base website font size is 10px.
Your environment
No response
Search keywords: space spacing units theme
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.