Remove opacity variables from :visited pseudo class (#7458)

* Support functions in pseudo variant list

* Remove text/border/bg color from :visited

* Update changelog
This commit is contained in:
Jordan Pittman 2022-02-14 13:24:18 -05:00 • committed by GitHub
parent 09d151f3f9
commit f116f9f664
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 5 deletions

View file

@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
- Nothing yet!
### Fixed
- Remove opacity variables from `:visited` pseudo class ([#7458](https://github.com/tailwindlabs/tailwindcss/pull/7458))
## [3.0.22] - 2022-02-11

View file

@ -70,7 +70,28 @@ export let variantPlugins = {
'only-of-type',
// State
'visited',
[
'visited',
({ container }) => {
let toRemove = ['--tw-text-opacity', '--tw-border-opacity', '--tw-bg-opacity']
container.walkDecls((decl) => {
if (toRemove.includes(decl.prop)) {
decl.remove()
return
}
for (const varName of toRemove) {
if (decl.value.includes(`/ var(${varName})`)) {
decl.value = decl.value.replace(`/ var(${varName})`, '')
}
}
})
return ':visited'
},
],
'target',
['open', '[open]'],
@ -100,15 +121,27 @@ export let variantPlugins = {
].map((variant) => (Array.isArray(variant) ? variant : [variant, `:${variant}`]))
for (let [variantName, state] of pseudoVariants) {
addVariant(variantName, `&${state}`)
addVariant(variantName, (ctx) => {
let result = typeof state === 'function' ? state(ctx) : state
return `&${result}`
})
}
for (let [variantName, state] of pseudoVariants) {
addVariant(`group-${variantName}`, `:merge(.group)${state} &`)
addVariant(`group-${variantName}`, (ctx) => {
let result = typeof state === 'function' ? state(ctx) : state
return `:merge(.group)${result} &`
})
}
for (let [variantName, state] of pseudoVariants) {
addVariant(`peer-${variantName}`, `:merge(.peer)${state} ~ &`)
addVariant(`peer-${variantName}`, (ctx) => {
let result = typeof state === 'function' ? state(ctx) : state
return `:merge(.peer)${result} ~ &`
})
}
},

View file

@ -539,3 +539,32 @@ it('variants for utilities should not be produced in a file without a utilities
`)
})
})
test('The visited variant removes opacity support', () => {
let config = {
content: [
{
raw: html`
<a class="visited:border-red-500 visited:bg-red-500 visited:text-red-500"
>Look, it's a link!</a
>
`,
},
],
plugins: [],
}
return run('@tailwind utilities', config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
.visited\:border-red-500:visited {
border-color: rgb(239 68 68);
}
.visited\:bg-red-500:visited {
background-color: rgb(239 68 68);
}
.visited\:text-red-500:visited {
color: rgb(239 68 68);
}
`)
})
})