Skip to content

Commit

Permalink
Add :read-only variant (#4102)
Browse files Browse the repository at this point in the history
* Add :read-only variant

* Added read-only variant to defaultConfig.stub

Co-authored-by: FunnyScarf <5177092+dyzajash@users.noreply.github.com>
  • Loading branch information
Mateusz and FunnyScarf committed May 11, 2021
1 parent 7991646 commit f89bf5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
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

0 comments on commit f89bf5f

Please sign in to comment.