Skip to content

Commit

Permalink
Add support for group and peer modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
reinink committed Oct 14, 2022
1 parent 6426a9d commit e74b23e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
21 changes: 17 additions & 4 deletions src/corePlugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,23 @@ export let variantPlugins = {
},

ariaVariants: ({ matchVariant, theme }) => {
let options = { values: theme('aria') ?? {} }
matchVariant('aria', (value) => `&[aria-${value}]`, options)
matchVariant('group-aria', (value) => `:merge(.group)[aria-${value}] &`, options)
matchVariant('peer-aria', (value) => `:merge(.peer)[aria-${value}] ~ &`, options)
matchVariant('aria', (value) => `&[aria-${value}]`, { values: theme('aria') ?? {} })
matchVariant(
'group-aria',
(value, { modifier }) =>
modifier
? `:merge(.group\\/${modifier})[aria-${value}] &`
: `:merge(.group)[aria-${value}] &`,
{ values: theme('aria') ?? {} }
)
matchVariant(
'peer-aria',
(value, { modifier }) =>
modifier
? `:merge(.peer\\/${modifier})[aria-${value}] ~ &`
: `:merge(.peer)[aria-${value}] ~ &`,
{ values: theme('aria') ?? {} }
)
},

orientationVariants: ({ addVariant }) => {
Expand Down
26 changes: 25 additions & 1 deletion tests/arbitrary-variants.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ test('variants without & or an at-rule are ignored', () => {

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

Expand Down Expand Up @@ -626,6 +626,12 @@ it('should support aria variants', () => {
<div class="aria-[sort=ascending]:underline"></div>
<div class="group-aria-checked:underline"></div>
<div class="peer-aria-checked:underline"></div>
<div class="group-aria-checked/foo:underline"></div>
<div class="peer-aria-checked/foo:underline"></div>
<div class="group-aria-[sort=ascending]:underline"></div>
<div class="peer-aria-[sort=ascending]:underline"></div>
<div class="group-aria-[sort=ascending]/foo:underline"></div>
<div class="peer-aria-[sort=ascending]/foo:underline"></div>
</div>
`,
},
Expand All @@ -648,9 +654,27 @@ it('should support aria variants', () => {
.group[aria-checked='true'] .group-aria-checked\:underline {
text-decoration-line: underline;
}
.group\/foo[aria-checked='true'] .group-aria-checked\/foo\:underline {
text-decoration-line: underline;
}
.group[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\:underline {
text-decoration-line: underline;
}
.group\/foo[aria-sort='ascending'] .group-aria-\[sort\=ascending\]\/foo\:underline {
text-decoration-line: underline;
}
.peer[aria-checked='true'] ~ .peer-aria-checked\:underline {
text-decoration-line: underline;
}
.peer\/foo[aria-checked='true'] ~ .peer-aria-checked\/foo\:underline {
text-decoration-line: underline;
}
.peer[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\:underline {
text-decoration-line: underline;
}
.peer\/foo[aria-sort='ascending'] ~ .peer-aria-\[sort\=ascending\]\/foo\:underline {
text-decoration-line: underline;
}
`)
})
})
Expand Down

0 comments on commit e74b23e

Please sign in to comment.