Skip to content

Commit

Permalink
Remove opacity variables from :visited pseudo class (#7458)
Browse files Browse the repository at this point in the history
* Support functions in pseudo variant list

* Remove text/border/bg color from :visited

* Update changelog
  • Loading branch information
thecrypticace authored Feb 14, 2022
1 parent 09d151f commit f116f9f
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 5 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

- Remove opacity variables from `:visited` pseudo class ([#7458](https://github.com/tailwindlabs/tailwindcss/pull/7458))

## [3.0.22] - 2022-02-11

Expand Down
41 changes: 37 additions & 4 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]'],

Expand Down Expand Up @@ -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} ~ &`
})
}
},

Expand Down
29 changes: 29 additions & 0 deletions tests/variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
`)
})
})

0 comments on commit f116f9f

Please sign in to comment.