diff --git a/src/corePlugins.js b/src/corePlugins.js index be2a106c2333..9756bf3a453d 100644 --- a/src/corePlugins.js +++ b/src/corePlugins.js @@ -153,6 +153,7 @@ export let variantPlugins = { } let variants = { + in: (_) => ['', ' &'], group: (_, { modifier }) => modifier ? [`:merge(${prefix('.group')}\\/${escapeClassName(modifier)})`, ' &'] @@ -442,6 +443,13 @@ export let variantPlugins = { }, }) + matchVariant('in-has', (value) => `:has(${normalize(value)}) &`, { + values: {}, + [INTERNAL_FEATURES]: { + respectPrefix: false, + }, + }) + matchVariant( 'group-has', (value, { modifier }) => @@ -473,6 +481,9 @@ export let variantPlugins = { ariaVariants: ({ matchVariant, theme }) => { matchVariant('aria', (value) => `&[aria-${normalize(value)}]`, { values: theme('aria') ?? {} }) + matchVariant('in-aria', (value) => `[aria-${normalize(value)}] &`, { + values: theme('aria') ?? {}, + }) matchVariant( 'group-aria', (value, { modifier }) => @@ -493,6 +504,9 @@ export let variantPlugins = { dataVariants: ({ matchVariant, theme }) => { matchVariant('data', (value) => `&[data-${normalize(value)}]`, { values: theme('data') ?? {} }) + matchVariant('in-data', (value) => `[data-${normalize(value)}] &`, { + values: theme('data') ?? {}, + }) matchVariant( 'group-data', (value, { modifier }) => diff --git a/tests/arbitrary-variants.test.js b/tests/arbitrary-variants.test.js index 0ab9e234c336..6124ba9e6fa7 100644 --- a/tests/arbitrary-variants.test.js +++ b/tests/arbitrary-variants.test.js @@ -602,12 +602,15 @@ it('should support aria variants', () => {
+ + + @@ -629,6 +632,9 @@ it('should support aria variants', () => { .aria-checked\:underline[aria-checked='true'], .aria-\[labelledby\=\'a_b\'\]\:underline[aria-labelledby='a b'], .aria-\[sort\=ascending\]\:underline[aria-sort='ascending'], + [aria-checked='true'] .in-aria-checked\:underline, + [aria-labelledby='a b'] .in-aria-\[labelledby\=\'a_b\'\]\:underline, + [aria-sort='ascending'] .in-aria-\[sort\=ascending\]\:underline, .group\/foo[aria-checked='true'] .group-aria-checked\/foo\:underline, .group[aria-checked='true'] .group-aria-checked\:underline, .group[aria-labelledby='a b'] .group-aria-\[labelledby\=\'a_b\'\]\:underline, @@ -659,10 +665,12 @@ it('should support data variants', () => { + + @@ -686,6 +694,8 @@ it('should support data variants', () => { .data-checked\:underline[data-ui~='checked'], .data-\[foo\=\'bar_baz\'\]\:underline[data-foo='bar baz'], .data-\[position\=top\]\:underline[data-position='top'], + [data-ui~='checked'] .in-data-checked\:underline, + [data-position='top'] .in-data-\[position\=top\]\:underline, .group\/foo[data-ui~='checked'] .group-data-checked\/foo\:underline, .group[data-ui~='checked'] .group-data-checked\:underline, .group[data-foo='bar baz'] .group-data-\[foo\=\'bar_baz\'\]\:underline, @@ -840,6 +850,30 @@ test('has-* variants with arbitrary values', () => { }) }) +test('in-has-* variants with arbitrary values', () => { + let config = { + theme: {}, + content: [ + { + raw: html``, + }, + ], + corePlugins: { preflight: false }, + } + + let input = css` + @tailwind utilities; + ` + + return run(input, config).then((result) => { + expect(result.css).toMatchFormattedCss(css` + :has(> h1 + .foo) .in-has-\[\>_h1_\+_\.foo\]\:block { + display: block; + } + `) + }) +}) + test('group-has-* variants with arbitrary values', () => { let config = { theme: {}, @@ -910,6 +944,58 @@ test('peer-has-* variants with arbitrary values', () => { }) }) +it('should be possible to use modifiers with in', () => { + let config = { + content: [ + { + raw: html` +