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

Add :read-only variant #4102

Merged
merged 9 commits into from May 11, 2021
1 change: 1 addition & 0 deletions src/lib/substituteVariantsAtRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ const defaultVariantGenerators = (config) => ({
hover: generatePseudoClassVariant('hover'),
'focus-within': generatePseudoClassVariant('focus-within'),
'focus-visible': generatePseudoClassVariant('focus-visible'),
'read-only': generatePseudoClassVariant('read-only'),
focus: generatePseudoClassVariant('focus'),
active: generatePseudoClassVariant('active'),
visited: generatePseudoClassVariant('visited'),
Expand Down
1 change: 1 addition & 0 deletions stubs/defaultConfig.stub.js
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,7 @@ module.exports = {
'visited',
'checked',
'empty',
'read-only',
'group-hover',
'group-focus',
'focus-within',
Expand Down
24 changes: 23 additions & 1 deletion tests/variantsAtRule.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,27 @@ test('it can generate hover, active and focus variants', () => {
})
})

test('it can generate read-only variants', () => {
const input = `
@variants read-only {
.banana { color: yellow; }
.chocolate { color: brown; }
}
`

const output = `
.banana { color: yellow; }
.chocolate { color: brown; }
.read-only\\:banana:read-only { color: yellow; }
.read-only\\:chocolate:read-only { color: brown; }
`

return run(input).then((result) => {
expect(result.css).toMatchCss(output)
expect(result.warnings().length).toBe(0)
})
})

test('it can generate hover, active and focus variants for multiple classes in one rule', () => {
const input = `
@variants hover, focus, active {
Expand Down Expand Up @@ -648,7 +669,7 @@ test('variants are generated in the order specified', () => {

test('the built-in variant pseudo-selectors are appended before any pseudo-elements', () => {
const input = `
@variants hover, focus-within, focus-visible, focus, active, group-hover {
@variants hover, focus-within, focus-visible, focus, active, group-hover, read-only {
.placeholder-yellow::placeholder { color: yellow; }
}
`
Expand All @@ -661,6 +682,7 @@ test('the built-in variant pseudo-selectors are appended before any pseudo-eleme
.focus\\:placeholder-yellow:focus::placeholder { color: yellow; }
.active\\:placeholder-yellow:active::placeholder { color: yellow; }
.group:hover .group-hover\\:placeholder-yellow::placeholder { color: yellow; }
.read-only\\:placeholder-yellow:read-only::placeholder { color: yellow; }
`

return run(input).then((result) => {
Expand Down