Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/src/pages/customization/breakpoints/breakpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ const styles = theme => ({

#### Arguments

1. `start` (*String*): A breakpoint key (`xs`, `sm`, etc.).
2. `end` (*String*): A breakpoint key (`xs`, `sm`, etc.).
1. `start` (*String*): A breakpoint key (`xs`, `sm`, etc.) or a screen width number in pixels.
2. `end` (*String*): A breakpoint key (`xs`, `sm`, etc.) or a screen width number in pixels.

#### Returns

Expand Down
13 changes: 9 additions & 4 deletions packages/material-ui/src/styles/createBreakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,20 @@ export default function createBreakpoints(breakpoints) {
}

function between(start, end) {
const endIndex = keys.indexOf(end) + 1;
const endIndex = keys.indexOf(end);

if (endIndex === keys.length) {
if (endIndex === keys.length - 1) {
return up(start);
}

return (
`@media (min-width:${values[start]}${unit}) and ` +
`(max-width:${values[keys[endIndex]] - step / 100}${unit})`
`@media (min-width:${
typeof values[start] === 'number' ? values[start] : start
}${unit}) and ` +
`(max-width:${(endIndex !== -1 && typeof values[keys[endIndex + 1]] === 'number'
? values[keys[endIndex + 1]]
: end) -
step / 100}${unit})`
);
}

Expand Down
9 changes: 8 additions & 1 deletion packages/material-ui/src/styles/createBreakpoints.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ describe('createBreakpoints', () => {
assert.strictEqual(breakpoints.down('md'), '@media (max-width:1279.95px)');
});

it('should use the specified key if it is not a recognized breakpoint', () => {
it('should accept a number', () => {
assert.strictEqual(breakpoints.down(600), '@media (max-width:599.95px)');
});

Expand All @@ -40,6 +40,13 @@ describe('createBreakpoints', () => {
);
});

it('should accept numbers', () => {
assert.strictEqual(
breakpoints.between(600, 800),
'@media (min-width:600px) and (max-width:799.95px)',
);
});

it('on xl should call up', () => {
assert.strictEqual(breakpoints.between('lg', 'xl'), '@media (min-width:1280px)');
});
Expand Down