Skip to content

Commit fd66e98

Browse files
authored
Fix to respect !important (#29)
1 parent aaee7ba commit fd66e98

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ function addColorSchemeMedia(isDark, propValue, declaration, postcss) {
2121
postcss.rule({
2222
nodes: [
2323
postcss.decl({
24+
important: declaration.important,
2425
prop: declaration.prop,
2526
value: propValue
2627
})

index.test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,30 @@ html:where(.is-light) {
407407
)
408408
})
409409

410+
test('transforms light-dark() with !important', () => {
411+
run(
412+
`html {
413+
border: 1px solid light-dark(white, black) !important
414+
}`,
415+
`@media (prefers-color-scheme:dark) {
416+
html:where(:not(.is-light)) {
417+
border: 1px solid black !important
418+
}
419+
}
420+
html:where(.is-dark) {
421+
border: 1px solid black !important
422+
}
423+
@media (prefers-color-scheme:light) {
424+
html:where(:not(.is-dark)) {
425+
border: 1px solid white !important
426+
}
427+
}
428+
html:where(.is-light) {
429+
border: 1px solid white !important
430+
}`
431+
)
432+
})
433+
410434
test('transforms nested light-dark()', () => {
411435
run(
412436
`html {

0 commit comments

Comments
 (0)