Skip to content

Commit

Permalink
Ensure complex variants with multiple classes work (#6311)
Browse files Browse the repository at this point in the history
* ensure complex variants with multiple classes work

* update changelog
  • Loading branch information
RobinMalfait authored Dec 10, 2021
1 parent 99baa6e commit 81f52a2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Ensure complex variants with multiple classes work [#6311](https://github.com/tailwindlabs/tailwindcss/pull/6311)

## [3.0.0] - 2021-12-09

Expand Down
4 changes: 2 additions & 2 deletions src/lib/expandApplyAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,10 @@ function processApply(root, context) {
// TODO: Should we use postcss-selector-parser for this instead?
function replaceSelector(selector, utilitySelectors, candidate) {
let needle = `.${escapeClassName(candidate)}`
let utilitySelectorsList = utilitySelectors.split(/\s*,\s*/g)
let utilitySelectorsList = utilitySelectors.split(/\s*\,(?![^(]*\))\s*/g)

return selector
.split(/\s*,\s*/g)
.split(/\s*\,(?![^(]*\))\s*/g)
.map((s) => {
let replaced = []

Expand Down
38 changes: 38 additions & 0 deletions tests/variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,44 @@ describe('custom advanced variants', () => {
`)
})
})

test('using multiple classNames in your custom variant', () => {
let config = {
content: [
{
raw: html` <div class="my-variant:underline test"></div> `,
},
],
plugins: [
function ({ addVariant }) {
addVariant('my-variant', '&:where(.one, .two, .three)')
},
],
}

let input = css`
@tailwind components;
@tailwind utilities;
@layer components {
.test {
@apply my-variant:italic;
}
}
`

return run(input, config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.test:where(.one, .two, .three) {
font-style: italic;
}
.my-variant\:underline:where(.one, .two, .three) {
text-decoration: underline;
}
`)
})
})
})

test('stacked peer variants', async () => {
Expand Down

0 comments on commit 81f52a2

Please sign in to comment.