diff --git a/src/corePlugins.js b/src/corePlugins.js index 90436e253..356ed7cde 100644 --- a/src/corePlugins.js +++ b/src/corePlugins.js @@ -127,7 +127,9 @@ export let variantPlugins = { // Interactive 'focus-within', - ['hover', config('shittyHover') ? '&:hover' : '@media (hover: hover) { &:hover }'], + 'hover', + ['@hover', '@media (hover: hover) { &:hover }'], + ['@hover-any', '@media (any-hover: hover) { &:hover }'], 'focus', 'focus-visible', 'active', diff --git a/tests/variants.test.js b/tests/variants.test.js index 31a97500a..363be229a 100644 --- a/tests/variants.test.js +++ b/tests/variants.test.js @@ -756,11 +756,16 @@ it('variants only picks the used selectors in a group (apply)', () => { }) }) -test('hover includes hover media feature by default', () => { +test('hover media feature variants', () => { let config = { content: [ { - raw: html`
`, + raw: html` +
+
+
+
+ `, }, ], corePlugins: { preflight: false }, @@ -776,34 +781,37 @@ test('hover includes hover media feature by default', () => { expect(result.css).toMatchFormattedCss(css` ${defaults} @media (hover: hover) { - .hover\:underline:hover, - .group:hover .group-hover\:underline, - .peer:hover ~ .peer-hover\:underline { - text-decoration-line: underline; + .can-hover\:block { + display: block; + } + } + @media (any-hover: hover) { + .any-hover\:flex { + display: flex; + } + } + @media (hover: none) { + .can-hover-none\:grid { + display: grid; + } + } + @media (any-hover: none) { + .any-hover-none\:hidden { + display: none; } } `) }) }) -test('legacy hover behavior using the config option', () => { +test('@hover includes hover media feature', () => { let config = { - hover: 'any', content: [ { - raw: html`
`, + raw: html`
`, }, ], corePlugins: { preflight: false }, - variants: { - hover: '&:hover', - }, - plugins: [ - // require('tailwindcss/hover-compat'), - // function ({ addVariant }) { - // addVariant('hover', '&:hover') - // }, - ], } let input = css` @@ -815,10 +823,58 @@ test('legacy hover behavior using the config option', () => { return run(input, config).then((result) => { expect(result.css).toMatchFormattedCss(css` ${defaults} - .hover\:underline:hover, - .group:hover .group-hover\:underline, - .peer:hover ~ .peer-hover\:underline { - text-decoration-line: underline; + @media (hover: hover) { + .\@hover\:block:hover { + display: block; + } + } + @media (hover: hover) { + .group:hover .group-\@hover\:flex { + display: flex; + } + } + @media (hover: hover) { + .peer:hover ~ .peer-\@hover\:grid { + display: grid; + } + } + `) + }) +}) + +test('@hover-any includes any-hover media feature', () => { + let config = { + content: [ + { + raw: html`
`, + }, + ], + corePlugins: { preflight: false }, + } + + let input = css` + @tailwind base; + @tailwind components; + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + ${defaults} + @media (any-hover: hover) { + .\@hover-any\:block:hover { + display: block; + } + } + @media (any-hover: hover) { + .group:hover .group-\@hover-any\:flex { + display: flex; + } + } + @media (any-hover: hover) { + .peer:hover ~ .peer-\@hover-any\:grid { + display: grid; + } } `) })