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

Allow variants with slashes in the name #10336

Merged
merged 2 commits into from Jan 16, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fix missing `blocklist` member in the `Config` type ([#10239](https://github.com/tailwindlabs/tailwindcss/pull/10239))
- Escape group names in selectors ([#10276](https://github.com/tailwindlabs/tailwindcss/pull/10276))
- Consider earlier variants before sorting functions ([#10288](https://github.com/tailwindlabs/tailwindcss/pull/10288))
- Allow variants with slashes ([#10336](https://github.com/tailwindlabs/tailwindcss/pull/10336))

### Changed

Expand Down
2 changes: 1 addition & 1 deletion src/lib/generateRules.js
Expand Up @@ -153,7 +153,7 @@ function applyVariant(variant, matches, context) {
// Retrieve "modifier"
{
let match = /(.*)\/(.*)$/g.exec(variant)
if (match) {
if (match && !context.variantMap.has(variant)) {
variant = match[1]
args.modifier = match[2]

Expand Down
70 changes: 70 additions & 0 deletions tests/variants.test.js
Expand Up @@ -1090,6 +1090,76 @@ test('variant functions returning arrays should output correct results when nest
`)
})

test('variants with slashes in them work', () => {
let config = {
content: [
{
raw: html` <div class="ar-1/10:text-red-500">ar-1/10</div> `,
},
],
theme: {
extend: {
screens: {
'ar-1/10': { raw: '(min-aspect-ratio: 1/10)' },
},
},
},
corePlugins: { preflight: false },
}

let input = css`
@tailwind utilities;
`

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@media (min-aspect-ratio: 1/10) {
.ar-1\/10\:text-red-500 {
--tw-text-opacity: 1;
color: rgb(239 68 68 / var(--tw-text-opacity));
}
}
`)
})
})

test('variants with slashes suspport modifiers', () => {
let config = {
content: [
{
raw: html` <div class="ar-1/10/20:text-red-500">ar-1/10</div> `,
},
],
corePlugins: { preflight: false },
plugins: [
function ({ matchVariant }) {
matchVariant(
'ar',
(value, { modifier }) => {
return [`@media (min-aspect-ratio: ${value}) and (foo: ${modifier})`]
},
{ values: { '1/10': '1/10' } }
)
},
],
}

let input = css`
@tailwind utilities;
`

return run(input, config).then((result) => {
expect(result.css).toMatchFormattedCss(css`
@media (min-aspect-ratio: 1/10) and (foo: 20) {
.ar-1\/10\/20\:text-red-500 {
--tw-text-opacity: 1;
color: rgb(239 68 68 / var(--tw-text-opacity));
}
}
`)
})
})

test('arbitrary variant selectors should not re-order scrollbar pseudo classes', async () => {
let config = {
content: [
Expand Down