question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Grid] Replace px to rem in spacing prop

See original GitHub issue

Now

<Grid spacing={8/padding: 4px|16/padding: 8px|32/padding: 16px|40/padding: 32px}>

Need

<Grid spacing={8/padding:0.25rem|16/padding:0.5rem|32/padding:0.75rem|40/padding:1rem}>

or add another prop spacingRem

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jul 31, 2019

@Und3Rdo9 It looks like that I have changed my mind a bit since last year 😃

1reaction
oliviertassinaricommented, Jul 29, 2019

@Und3Rdo9 Oh, that’s a bug! We could imagine the following change:

diff --git a/packages/material-ui/src/Grid/Grid.js b/packages/material-ui/src/Grid/Grid.js
index 9fa4d375f..c59765def 100644
--- a/packages/material-ui/src/Grid/Grid.js
+++ b/packages/material-ui/src/Grid/Grid.js
@@ -74,11 +74,16 @@ function generateGutter(theme, breakpoint) {
       return;
     }

+    const half =
+      typeof themeSpacing === 'number'
+        ? themeSpacing / 2
+        : themeSpacing.replace(/(\d+\.\d+)/, (str, p1) => p1 / 2);
+
     styles[`spacing-${breakpoint}-${spacing}`] = {
-      margin: -themeSpacing / 2,
+      margin: -half,
       width: `calc(100% + ${themeSpacing}px)`,
       '& > $item': {
-        padding: themeSpacing / 2,
+        padding: half,
       },
     };
   });
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Grid] Replace px to rem in spacing prop · Issue #11910 - GitHub
I changed the spacing function to output a rem string as per the 'bootstrap strategy' example(https://material-ui.com/customization/spacing/).
Read more >
Why designers should move from px to rem (and how to do ...
So to answer our original question, “what changes in our design when using rem instead of px ”. The answer is, for all...
Read more >
Use `rem` for Global Sizing; Use `em` for Local Sizing
The spacing between the paragraphs will depend on the size of the paragraph text, so you could feasibly set that spacing in either...
Read more >
Should I use px or rem value units in my CSS? - Stack Overflow
My big quibble with this argument is that when adjusting font size and spacing at responsive breakpoints you can set a new font...
Read more >
Rem in CSS: Understanding and Using rem Units - SitePoint
Using rem can help ensure consistency of font size and spacing throughout your UI. According to the W3C spec the definition for one...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found