Skip to content
This repository has been archived by the owner on Feb 22, 2022. It is now read-only.

Commit

Permalink
Add group-focus-visible variant (fix #9)
Browse files Browse the repository at this point in the history
  • Loading branch information
benface committed Aug 4, 2020
1 parent 95dc464 commit ce7da0d
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project mostly adheres to [Semantic Versioning](https://semver.org/spec

## [5.0.0] - 2020-08-04

### Added
- Added a `group-focus-visible` variant

### Removed
- Removed the `checked` variant since it is built into Tailwind as of v1.5

Expand Down Expand Up @@ -69,7 +72,8 @@ No change since 2.0.0-beta.1

Initial release

[Unreleased]: https://github.com/benface/tailwindcss-interaction-variants/compare/v4.0.0...HEAD
[Unreleased]: https://github.com/benface/tailwindcss-interaction-variants/compare/v5.0.0...HEAD
[5.0.0]: https://github.com/benface/tailwindcss-interaction-variants/compare/v4.0.0...v5.0.0
[4.0.0]: https://github.com/benface/tailwindcss-interaction-variants/compare/v3.1.1...v4.0.0
[3.1.1]: https://github.com/benface/tailwindcss-interaction-variants/compare/v3.1.0...v3.1.1
[3.1.0]: https://github.com/benface/tailwindcss-interaction-variants/compare/v3.0.0...v3.1.0
Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = {
},
},
variants: {
backgroundColor: ['group-focus-within', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus', 'can-hover', 'no-hover'],
backgroundColor: ['group-focus-within', 'group-focus-visible', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus', 'can-hover', 'no-hover'],
},
plugins: [
require('tailwindcss-interaction-variants'),
Expand All @@ -44,6 +44,10 @@ The above configuration would generate the following CSS:
background-color: black;
}

.group:focus-visible .group-focus-visible\:bg-black {
background-color: black;
}

.group:active .group-active\:bg-black {
background-color: black;
}
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ module.exports = plugin(function({ addVariant, config, e, postcss }) {
};

addVariant('group-focus-within', groupPseudoClassVariant('focus-within'));
addVariant('group-focus-visible', groupPseudoClassVariant('focus-visible'));
addVariant('group-active', groupPseudoClassVariant('active'));
addVariant('group-visited', groupPseudoClassVariant('visited'));
addVariant('group-disabled', groupPseudoClassVariant('disabled'));
Expand Down
13 changes: 11 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,17 @@ test('the no-hover variant is working', () => {
});

test('all the variants are working', () => {
return generatePluginCss(['group-focus-within', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus', 'can-hover', 'no-hover']).then(css => {
return generatePluginCss(['group-focus-within', 'group-focus-visible', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus', 'can-hover', 'no-hover']).then(css => {
expect(css).toMatchCss(`
.w-1\\/2 {
width: 50%;
}
.group:focus-within .group-focus-within\\:w-1\\/2 {
width: 50%;
}
.group:focus-visible .group-focus-visible\\:w-1\\/2 {
width: 50%;
}
.group:active .group-active\\:w-1\\/2 {
width: 50%;
}
Expand Down Expand Up @@ -143,14 +146,17 @@ test('all the variants are working', () => {
});

test('all variants can be chained with the responsive variant', () => {
return generatePluginCss(['group-focus-within', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus', 'can-hover', 'no-hover', 'responsive']).then(css => {
return generatePluginCss(['group-focus-within', 'group-focus-visible', 'group-active', 'group-visited', 'group-disabled', 'hocus', 'group-hocus', 'can-hover', 'no-hover', 'responsive']).then(css => {
expect(css).toMatchCss(`
.w-1\\/2 {
width: 50%;
}
.group:focus-within .group-focus-within\\:w-1\\/2 {
width: 50%;
}
.group:focus-visible .group-focus-visible\\:w-1\\/2 {
width: 50%;
}
.group:active .group-active\\:w-1\\/2 {
width: 50%;
}
Expand Down Expand Up @@ -183,6 +189,9 @@ test('all variants can be chained with the responsive variant', () => {
.group:focus-within .sm\\:group-focus-within\\:w-1\\/2 {
width: 50%;
}
.group:focus-visible .sm\\:group-focus-visible\\:w-1\\/2 {
width: 50%;
}
.group:active .sm\\:group-active\\:w-1\\/2 {
width: 50%;
}
Expand Down

0 comments on commit ce7da0d

Please sign in to comment.