Skip to content

Commit 7a5bc97

Browse files
committed
Merge branch 'spiltcoffee-variant-fix'
2 parents 3e55b9a + eeb7886 commit 7a5bc97

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

__tests__/variantsAtRule.test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,31 @@ test('it can generate hover, active and focus variants', () => {
139139
})
140140
})
141141

142+
test('it can generate hover, active and focus variants for multiple classes in one rule', () => {
143+
const input = `
144+
@variants hover, focus, active {
145+
.banana, .lemon { color: yellow; }
146+
.chocolate, .coconut { color: brown; }
147+
}
148+
`
149+
150+
const output = `
151+
.banana, .lemon { color: yellow; }
152+
.chocolate, .coconut { color: brown; }
153+
.hover\\:banana:hover, .hover\\:lemon:hover { color: yellow; }
154+
.hover\\:chocolate:hover, .hover\\:coconut:hover { color: brown; }
155+
.focus\\:banana:focus, .focus\\:lemon:focus { color: yellow; }
156+
.focus\\:chocolate:focus, .focus\\:coconut:focus { color: brown; }
157+
.active\\:banana:active, .active\\:lemon:active { color: yellow; }
158+
.active\\:chocolate:active, .active\\:coconut:active { color: brown; }
159+
`
160+
161+
return run(input).then(result => {
162+
expect(result.css).toMatchCss(output)
163+
expect(result.warnings().length).toBe(0)
164+
})
165+
})
166+
142167
test('it wraps the output in a responsive at-rule if responsive is included as a variant', () => {
143168
const input = `
144169
@variants responsive, hover, focus {

src/util/generateVariantFunction.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export default function generateVariantFunction(generator) {
1313
separator: escapeClassName(config.options.separator),
1414
modifySelectors: modifierFunction => {
1515
cloned.walkRules(rule => {
16-
rule.selector = modifierFunction({
17-
className: rule.selector.slice(1),
18-
selector: rule.selector,
19-
})
16+
rule.selectors = rule.selectors.map(selector =>
17+
modifierFunction({
18+
className: selector.slice(1),
19+
selector,
20+
})
21+
)
2022
})
2123
return cloned
2224
},

0 commit comments

Comments
 (0)