Skip to content

Commit 759a494

Browse files
authored
Merge pull request #600 from system-ui/css-media-order
Adjust media query sort logic
2 parents 6de957c + 16a0481 commit 759a494

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

packages/css/src/index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,12 @@ const responsive = styles => theme => {
162162
}
163163
for (let i = 0; i < value.slice(0, mediaQueries.length).length; i++) {
164164
const media = mediaQueries[i]
165-
if (value[i] == null) {
166-
next[media] = {}
167-
continue
168-
}
169165
if (!media) {
170166
next[key] = value[i]
171167
continue
172168
}
173169
next[media] = next[media] || {}
170+
if (value[i] == null) continue
174171
next[media][key] = value[i]
175172
}
176173
}

packages/css/test/index.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,3 +432,27 @@ test('returns correct media query order', () => {
432432
color: 'red',
433433
})
434434
})
435+
436+
test('returns correct media query order 2', () => {
437+
const result = css({
438+
flexDirection: 'column',
439+
justifyContent: [null, 'flex-start', 'flex-end'],
440+
color: 'background',
441+
height: '100%',
442+
px: [2, 3, 4],
443+
py: 4,
444+
})(theme)
445+
const keys = Object.keys(result)
446+
expect(keys).toEqual([
447+
'flexDirection',
448+
'justifyContent',
449+
'@media screen and (min-width: 40em)',
450+
'@media screen and (min-width: 52em)',
451+
'color',
452+
'height',
453+
'paddingLeft',
454+
'paddingRight',
455+
'paddingTop',
456+
'paddingBottom',
457+
])
458+
})

0 commit comments

Comments
 (0)