Material-ui: [Theme] spacing() with no args returns empty string

Created on 30 Apr 2019  路  4Comments  路  Source: mui-org/material-ui

Using theme.spacing() without any args returns a empty string. To get the default value it should be given 1 in the args.

  • [x] This is not a v0.x issue.
  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior 馃

theme.spacing() should give default spacing value.

Current Behavior 馃槸

theme.spacing() returns empty string.

Your Environment 馃寧

| Tech | Version |
|--------------|---------|
| Material-UI | 4.0.0-beta.0 |
| React | 16.8.6 |
| Browser | Chromium: 74.0.3729.108 |

discussion

Most helpful comment

@vkasraj We need to change something, I agree. We have two options. We improve the warning, or we support a default factor of 1. I'm slightly leaning toward the default value path.

@oliviertassinari I also vote for the default value.

All 4 comments

@vkasraj Interesting proposal. We could support it with a simple change:

--- a/packages/material-ui/src/styles/createSpacing.js
+++ b/packages/material-ui/src/styles/createSpacing.js
@@ -22,7 +22,7 @@ export default function createSpacing(spacingInput = 8) {
         'It should be a number or a function.',
       ].join('\n'),
     );
-    transform = factor => {
+    transform = (factor = 1) => {
       warning(
         typeof factor === 'number',
         `Expected spacing argument to be a number, got ${factor}`,

But what's the motivation for not doing theme.spacing(1)?

@oliviertassinari Currently I am doing theme.spacing(1) to get the default value. But, passing 1 every time seems redundant. Also If someone doesn't pass any args, It silently failed because empty string returned from the function. So, It is better to return the default value.

@vkasraj We need to change something, I agree. We have two options. We improve the warning, or we support a default factor of 1. I'm slightly leaning toward the default value path.

@vkasraj We need to change something, I agree. We have two options. We improve the warning, or we support a default factor of 1. I'm slightly leaning toward the default value path.

@oliviertassinari I also vote for the default value.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

reflog picture reflog  路  3Comments

ghost picture ghost  路  3Comments

ghost picture ghost  路  3Comments

pola88 picture pola88  路  3Comments

newoga picture newoga  路  3Comments