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.

Make theme.breakpoints function to take a delta

See original GitHub issue

Quick to the point

Could be a nice feature if functions inside the theme.breakpoints take a delta? So: if my “lg” is at “1024px” calling theme.breakpoints.up('lg', -10) will means “1014”?

My usecase

I’m building a layout where I’m controlling offcanvas icon to “move-in” from a certain resolution.

Let me attach a demo gif to better explain the issue

m-ui-brakpoints demo

I’m applying a style like the following:

  stickyToolbar: {
    position: 'fixed',
    right: theme.spacing(-5),
    // ...
    [theme.breakpoints.up('lg')]: {
      right: theme.spacing(1),
    },
    transition: 'right 300ms ease-in',
  },

So: my scope is to keep button offcanvas until the main content stop expading so we have enough external space to keep it (so at lg size and up).

The small issue I’ve. The media-query start applying at lg, but I don’t have enough space at “lg+1px” to host the whole button.

I can obviously wite the mediaquery myself manually, but this will be less dynamic in case I need to change default theme settings.


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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

3reactions
merceyzcommented, Aug 2, 2019

Wow! I was not aware that theme.breakpoints.up and similar functions can receive a number. This seems not documented at https://material-ui.com/customization/breakpoints/

The TypeScript type definitions specify it here, so if you’re using an editor like VSCode it should show that to you https://github.com/mui-org/material-ui/blob/14bbd57c5fe1d9be367fe3ccfdc84736d511f094/packages/material-ui/src/styles/createBreakpoints.d.ts#L8-L9

Something like [theme.breakpoints.up(theme.breakpoints.values.lg + (props => (props.foo ? 10 : 20)))] seems not supported.

Here is a way to control it dynamically using props

stickyToolbar: props => ({
  position: "fixed",
  right: theme.spacing(-5),
  // ...
  [theme.breakpoints.up(theme.breakpoints.values.lg + props.foo ? 10 : 20)]: {
    right: theme.spacing(1)
  },
  transition: "right 300ms ease-in"
})
1reaction
merceyzcommented, Aug 2, 2019

It would only work in JS when directly accessing the theme in makeStyles and withStyles

Read more comments on GitHub >

github_iconTop Results From Across the Web

Make theme.breakpoints function to take a delta · Issue #16848
So: if my "lg" is at "1024px" calling theme.breakpoints.up('lg', -10) will means ... Make theme.breakpoints function to take a delta #16848.
Read more >
Breakpoints - Material UI - MUI
theme.breakpoints.values : Default to the above values. The keys are your screen names, and the values are the min-width where that breakpoint should...
Read more >
How to set breakpoints when overriding theme variables in ...
You can use custom breakpoints with createBreakpoints. Here is an example changing the MuiButton
Read more >
Using Breakpoints and Media Queries in Material-UI
Basically, we will pass in a breakpoint as an argument, and this will return a media query for us. For example, if we...
Read more >
MPLAB® X IDE Breakpoints - Developer Help
Make MPLAB X IDE Run Faster ... The Preferred Method to Use Loadables · Loadable Projects and Files: ... Sigma-Delta Analog to Digital...
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