Skip to content

Commit

Permalink
feat(nested selectors): use :where css selector
Browse files Browse the repository at this point in the history
  • Loading branch information
zirbest committed Jul 1, 2023
1 parent 7c86cea commit a722803
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function presetPrimitives(options: PrimitivesOptions = {}): Preset {
return {
matcher: matcher.slice(match[0].length),
selector: (s: any) => (match[1] === '-not')
? `${s}[${selector}]:not(${attrGen})`
: `${s}${attrGen}`,
? `${s}[${selector}]:not(${attrGen}),:where([${selector}]:not(${attrGen})) ${s}:not(${selector})`
: `${s}${attrGen},:where(${attrGen}) ${s}`,
}
}
else {
Expand Down
8 changes: 4 additions & 4 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('unocss-preset-primitives', () => {
test('should generate css for an exposed state', async () => {
const { css } = await uno
.generate('<div class="ui-open:foo"></div>', { preflights: false, minify: true })
expect(css).toMatch(`.${e('ui-open:foo')}[data-headlessui-state~='open']{name:bar;}`)
expect(css).toMatchInlineSnapshot('".ui-open\\\\:foo[data-headlessui-state~=\'open\'],:where([data-headlessui-state~=\'open\']) .ui-open\\\\:foo{name:bar;}"')
})
})

Expand All @@ -24,7 +24,7 @@ describe('unocss-preset-headlessui', () => {
test('should generate css for an exposed state', async () => {
const { css } = await uno
.generate('<div class="ui-open:foo"></div>', { preflights: false, minify: true })
expect(css).toMatch(`.${e('ui-open:foo')}[data-headlessui-state~='open']{name:bar;}`)
expect(css).toMatchInlineSnapshot('".ui-open\\\\:foo[data-headlessui-state~=\'open\'],:where([data-headlessui-state~=\'open\']) .ui-open\\\\:foo{name:bar;}"')
})
})

Expand All @@ -37,7 +37,7 @@ describe('unocss-preset-radixui', () => {
test('should generate css for an exposed state', async () => {
const { css } = await uno
.generate('<div class="ui-open:foo"></div>', { preflights: false, minify: true })
expect(css).toMatch(`.${e('ui-open:foo')}[data-state~='open']{name:bar;}`)
expect(css).toMatchInlineSnapshot('".ui-open\\\\:foo[data-state~=\'open\'],:where([data-state~=\'open\']) .ui-open\\\\:foo{name:bar;}"')
})
})

Expand All @@ -50,6 +50,6 @@ describe('unocss-preset-kobalte', () => {
test('should generate css for an exposed state', async () => {
const { css } = await uno
.generate('<div class="ui-selected:foo"></div>', { preflights: false, minify: true })
expect(css).toMatch(`.${e('ui-selected:foo')}[data-selected]{name:bar;}`)
expect(css).toMatchInlineSnapshot('".ui-selected\\\\:foo[data-selected],:where([data-selected]) .ui-selected\\\\:foo{name:bar;}"')
})
})

0 comments on commit a722803

Please sign in to comment.