Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure complex variants with multiple classes work #6311

Merged
merged 2 commits into from
Dec 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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