Skip to content

Commit f116f9f

Browse files
Remove opacity variables from :visited pseudo class (#7458)
* Support functions in pseudo variant list * Remove text/border/bg color from :visited * Update changelog
1 parent 09d151f commit f116f9f

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Remove opacity variables from `:visited` pseudo class ([#7458](https://github.com/tailwindlabs/tailwindcss/pull/7458))
1113

1214
## [3.0.22] - 2022-02-11
1315

src/corePlugins.js

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,28 @@ export let variantPlugins = {
7070
'only-of-type',
7171

7272
// State
73-
'visited',
73+
[
74+
'visited',
75+
({ container }) => {
76+
let toRemove = ['--tw-text-opacity', '--tw-border-opacity', '--tw-bg-opacity']
77+
78+
container.walkDecls((decl) => {
79+
if (toRemove.includes(decl.prop)) {
80+
decl.remove()
81+
82+
return
83+
}
84+
85+
for (const varName of toRemove) {
86+
if (decl.value.includes(`/ var(${varName})`)) {
87+
decl.value = decl.value.replace(`/ var(${varName})`, '')
88+
}
89+
}
90+
})
91+
92+
return ':visited'
93+
},
94+
],
7495
'target',
7596
['open', '[open]'],
7697

@@ -100,15 +121,27 @@ export let variantPlugins = {
100121
].map((variant) => (Array.isArray(variant) ? variant : [variant, `:${variant}`]))
101122

102123
for (let [variantName, state] of pseudoVariants) {
103-
addVariant(variantName, `&${state}`)
124+
addVariant(variantName, (ctx) => {
125+
let result = typeof state === 'function' ? state(ctx) : state
126+
127+
return `&${result}`
128+
})
104129
}
105130

106131
for (let [variantName, state] of pseudoVariants) {
107-
addVariant(`group-${variantName}`, `:merge(.group)${state} &`)
132+
addVariant(`group-${variantName}`, (ctx) => {
133+
let result = typeof state === 'function' ? state(ctx) : state
134+
135+
return `:merge(.group)${result} &`
136+
})
108137
}
109138

110139
for (let [variantName, state] of pseudoVariants) {
111-
addVariant(`peer-${variantName}`, `:merge(.peer)${state} ~ &`)
140+
addVariant(`peer-${variantName}`, (ctx) => {
141+
let result = typeof state === 'function' ? state(ctx) : state
142+
143+
return `:merge(.peer)${result} ~ &`
144+
})
112145
}
113146
},
114147

tests/variants.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,3 +539,32 @@ it('variants for utilities should not be produced in a file without a utilities
539539
`)
540540
})
541541
})
542+
543+
test('The visited variant removes opacity support', () => {
544+
let config = {
545+
content: [
546+
{
547+
raw: html`
548+
<a class="visited:border-red-500 visited:bg-red-500 visited:text-red-500"
549+
>Look, it's a link!</a
550+
>
551+
`,
552+
},
553+
],
554+
plugins: [],
555+
}
556+
557+
return run('@tailwind utilities', config).then((result) => {
558+
return expect(result.css).toMatchFormattedCss(css`
559+
.visited\:border-red-500:visited {
560+
border-color: rgb(239 68 68);
561+
}
562+
.visited\:bg-red-500:visited {
563+
background-color: rgb(239 68 68);
564+
}
565+
.visited\:text-red-500:visited {
566+
color: rgb(239 68 68);
567+
}
568+
`)
569+
})
570+
})

0 commit comments

Comments
 (0)