Skip to content

Commit 763ee71

Browse files
committed
Ensure all selectors in a rule receive important scope
1 parent 19c74b1 commit 763ee71

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

__tests__/processPlugins.test.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,7 @@ test('plugins respect prefix and important options by default when adding utilit
877877
`)
878878
})
879879

880-
test('plugins respect prefix and important (selector) options by default when adding utilities', () => {
880+
test('when important is a selector it is used to scope utilities instead of adding !important', () => {
881881
const { utilities } = processPlugins(
882882
[
883883
function({ addUtilities }) {
@@ -889,14 +889,38 @@ test('plugins respect prefix and important (selector) options by default when ad
889889
},
890890
],
891891
makeConfig({
892-
prefix: 'tw-',
893892
important: '#app',
894893
})
895894
)
896895

897896
expect(css(utilities)).toMatchCss(`
898897
@variants {
899-
#app .tw-rotate-90 {
898+
#app .rotate-90 {
899+
transform: rotate(90deg)
900+
}
901+
}
902+
`)
903+
})
904+
905+
test('when important is a selector it scopes all selectors in a rule, even though defining utilities like this is stupid', () => {
906+
const { utilities } = processPlugins(
907+
[
908+
function({ addUtilities }) {
909+
addUtilities({
910+
'.rotate-90, .rotate-1\\/4': {
911+
transform: 'rotate(90deg)',
912+
},
913+
})
914+
},
915+
],
916+
makeConfig({
917+
important: '#app',
918+
})
919+
)
920+
921+
expect(css(utilities)).toMatchCss(`
922+
@variants {
923+
#app .rotate-90, #app .rotate-1\\/4 {
900924
transform: rotate(90deg)
901925
}
902926
}

src/util/processPlugins.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ export default function(plugins, config) {
5959
if (config.important === true) {
6060
rule.walkDecls(decl => (decl.important = true))
6161
} else if (typeof config.important === 'string') {
62-
rule.selector = increaseSpecificity(config.important, rule.selector)
62+
rule.selectors = rule.selectors.map(selector => {
63+
return increaseSpecificity(config.important, selector)
64+
})
6365
}
6466
}
6567
})

0 commit comments

Comments
 (0)