Skip to content

Commit e74b23e

Browse files
committed
Add support for group and peer modifiers
1 parent 6426a9d commit e74b23e

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

src/corePlugins.js

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,23 @@ export let variantPlugins = {
258258
},
259259

260260
ariaVariants: ({ matchVariant, theme }) => {
261-
let options = { values: theme('aria') ?? {} }
262-
matchVariant('aria', (value) => `&[aria-${value}]`, options)
263-
matchVariant('group-aria', (value) => `:merge(.group)[aria-${value}] &`, options)
264-
matchVariant('peer-aria', (value) => `:merge(.peer)[aria-${value}] ~ &`, options)
261+
matchVariant('aria', (value) => `&[aria-${value}]`, { values: theme('aria') ?? {} })
262+
matchVariant(
263+
'group-aria',
264+
(value, { modifier }) =>
265+
modifier
266+
? `:merge(.group\\/${modifier})[aria-${value}] &`
267+
: `:merge(.group)[aria-${value}] &`,
268+
{ values: theme('aria') ?? {} }
269+
)
270+
matchVariant(
271+
'peer-aria',
272+
(value, { modifier }) =>
273+
modifier
274+
? `:merge(.peer\\/${modifier})[aria-${value}] ~ &`
275+
: `:merge(.peer)[aria-${value}] ~ &`,
276+
{ values: theme('aria') ?? {} }
277+
)
265278
},
266279

267280
orientationVariants: ({ addVariant }) => {

tests/arbitrary-variants.test.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ test('variants without & or an at-rule are ignored', () => {
107107

108108
test('arbitrary variants are sorted after other variants', () => {
109109
let config = {
110-
content: [{ raw: html`<div class="underline lg:underline [&>*]:underline"></div>` }],
110+
content: [{ raw: html`<div class="[&>*]:underline underline lg:underline"></div>` }],
111111
corePlugins: { preflight: false },
112112
}
113113

@@ -626,6 +626,12 @@ it('should support aria variants', () => {
626626
<div class="aria-[sort=ascending]:underline"></div>
627627
<div class="group-aria-checked:underline"></div>
628628
<div class="peer-aria-checked:underline"></div>
629+
<div class="group-aria-checked/foo:underline"></div>
630+
<div class="peer-aria-checked/foo:underline"></div>
631+
<div class="group-aria-[sort=ascending]:underline"></div>
632+
<div class="peer-aria-[sort=ascending]:underline"></div>
633+
<div class="group-aria-[sort=ascending]/foo:underline"></div>
634+
<div class="peer-aria-[sort=ascending]/foo:underline"></div>
629635
</div>
630636
`,
631637
},
@@ -648,9 +654,27 @@ it('should support aria variants', () => {
648654
.group[aria-checked='true'] .group-aria-checked\:underline {
649655
text-decoration-line: underline;
650656
}
657+
.group\/foo[aria-checked='true'] .group-aria-checked\/foo\:underline {
658+
text-decoration-line: underline;
659+
}
660+
.group[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\:underline {
661+
text-decoration-line: underline;
662+
}
663+
.group\/foo[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\/foo\:underline {
664+
text-decoration-line: underline;
665+
}
651666
.peer[aria-checked='true'] ~ .peer-aria-checked\:underline {
652667
text-decoration-line: underline;
653668
}
669+
.peer\/foo[aria-checked='true'] ~ .peer-aria-checked\/foo\:underline {
670+
text-decoration-line: underline;
671+
}
672+
.peer[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\:underline {
673+
text-decoration-line: underline;
674+
}
675+
.peer\/foo[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\/foo\:underline {
676+
text-decoration-line: underline;
677+
}
654678
`)
655679
})
656680
})

0 commit comments

Comments
 (0)