[theme] Remove hardcoded breakpoints
See original GitHub issueThere are several places in the codebase where breakpoints are hardcoded. Since we have the ability to override breakpoints, we should not have hardcoded values in the code
- 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 😯
- PropTypes
PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl']),
PropTypes.arrayOf(PropTypes.oneOf(['xs', 'sm', 'md', 'lg', 'xl'])),
- Styles
[theme.breakpoints.only('xs')]: {
...
}
- Functions in withWidth.js
import { breakpointKeys } from '../styles/createBreakpoints';
function isWidthUp(...){
return breakpointKeys.indexOf(...)
}
function isWidthDown(...){
return breakpointKeys.indexOf(...)
}
Expected Behavior 🤔
- PropTypes
PropTypes.string
PropTypes.arrayOf(PropTypes.string),
- Styles
a) Use a media query only if there is such a breakpoint in the theme
[theme.breakpoints.only(theme.breakpoints.keys['xs'] ?? 0)]: {
...
}
b) Add a new property alias
to createBreakpoints
function to match breakpoints
createBreakpoints({
values: {
tablet: 640,
laptop: 1024,
desktop: 1280,
},
alias: {
xs: 'tablet',
sm: 'tablet',
},
}
})
- Functions in withWidth.js
a) Show the necessity for breakpoints
Remove
import { breakpointKeys } from '../styles/createBreakpoints'
;
function isWidthUp(breakpoints, breakpoint, width, inclusive = true){ .. }
b) Add breakpoints to options implicitly
import { breakpointKeys } from '../styles/createBreakpoints'
function isWidthUp(breakpoint, width, opts = {}) {
let {breakpoints = breakpointKeys, inclusive = true } = opts;
...
}
Your Environment 🌎
Tech | Version |
---|---|
Material-UI | v4.11.0 |
Issue Analytics
- State:
- Created 3 years ago
- Reactions:5
- Comments:11 (11 by maintainers)
Top Results From Across the Web
Clear / Remove a Data Breakpoint
If you want to remove all breakpoints, right click anywhere in the Breakpoints window and select Delete All from the popup menu. Click...
Read more >How to remove the breakpoints?
Real quick way to get rid of all breakpoints in all programs or function modules, is to simply log off the system completely(all...
Read more >Set or remove breakpoints
Right-click a conditional breakpoint and select Remove breakpoint to remove it. From the Syntax Editor toolbar, click the Open Script Debugger ...
Read more >How do I change the responsive breakpoint on Theme?
There are hard coded breakpoints in the stylesheet so there might not be an easy way around this. You can set the mobile...
Read more >ba (Break on Access) - Windows drivers
The ba command sets a processor breakpoint (often called, ... the breakpoint is permanently removed from the breakpoint list. /p EProcess
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @oliviertassinari , anyone is working on it? Can I take this up?
This is still an issue in v5. Looks like there has not been any movement on this in a couple years. I implemented custom breakpoints as shown in the example and noticed some peculiar diffs in my snapshot tests for a Tabs component
Turned out that tabs was using
theme.breakpoints.down('sm')
under the hood.My solution was to add back the breakpoints for xs, sm, md, lg, xl and duplicate the values from other breakpoints, and then hide them from TS. Would be nice if this could be fixed with aliasing. In the meantime, it seems prudent to at least add some sort of note in the documentation.
Perhaps we should start the first suggestion you provided in this comment https://github.com/mui/material-ui/issues/21778#issuecomment-657225142. IMO adding an aliases object to the breakpoints (like your second example) feels like a more stable solution, but updating the docs seems good enough.
I’m happy to make a PR to update the docs. I could also work on the second option of adding an aliases property to the breakpoints object, but I might be a little slower getting that PR ready since I don’t have a lot of free time right now.