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.

[Theming] theme.spacing doesn't accept multiple string arguments

See original GitHub issue

Using a custom function for theme.spacing with multiple arguments (theme.spacing("xs", "sm")) used to work in v4.8, now it doesn’t.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

Given a custom spacing function like:

const customSpacing = key => {
  const mySpacings = { xs: 10, sm: 30, lg: 50 };
  return mySpacings[key] || key;
};

And applying it like so: padding: theme.spacing("sm", "xs")

The output is: padding: sm xs image

Expected Behavior 🤔

Expected the output to be padding: 30px 10px

Steps to Reproduce 🕹

CodeSandbox of the example above: https://codesandbox.io/s/material-demo-sv3h3?file=/demo.js:430-455

If you change to "@material-ui/core": "~4.8.0" it works fine

Steps:

  1. Notice how the div padding isn’t properly applied (inspect the red div element)

Context 🔦

Your Environment 🌎

Tech Version
Material-UI v4.10.0
React
Browser
TypeScript
etc.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
oliviertassinaricommented, Jun 2, 2020

As I user, I expected that by using a custom function, its result wouldn’t be “hijacked” in some special cases

@zettca Thanks for sharing more details on how you use the spacing function. I think that we all agree that it’s the desired direction to go into. The question at stake is: how?

0reactions
GuilleDFcommented, Oct 23, 2020

I can implement @oliviertassinari’s proposed solution, if that’s okay with you guys 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Theming] theme.spacing doesn't accept multiple string ...
Using a custom function for theme.spacing with multiple arguments ( theme.spacing("xs", "sm") ) used to work in v4.8 , now it doesn't.
Read more >
how theme.spacing() is functioning? - Stack Overflow
const theme = createMuiTheme({ spacing: 8, });. When your theme is define, you have a spacing value. By default this value is 8px...
Read more >
Spacing - Material UI - MUI
Use the theme.spacing() helper to create consistent spacing between the elements ... Multiple arity. The theme.spacing() helper accepts up to 4 arguments.
Read more >
API Reference - styled-components
Returns a function that accepts a tagged template literal and turns it into a ... will receive the styled component's props as the...
Read more >
Global Styling with Material-UI Theme Overrides and Props
Learn how to use global CSS overrides and default props in a theme to customize all instances of a Material-UI component in a...
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