Skip to content

Commit

Permalink
(fix) Fixes the :has and other selector when used with multiple (fixe…
Browse files Browse the repository at this point in the history
…s#596) (#597)
  • Loading branch information
cristianbote authored Oct 11, 2024
1 parent e01d969 commit 907ee0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/__tests__/integrations.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ describe('integrations', () => {
const BoxWithShared = styled('div')(shared);
const BoxWithSharedAndConditional = styled('div')([shared, { baz: 0 }]);

const BoxWithHas = styled('div')`
label:has(input, select),
:has(foo, boo) {
color: red;
}
`;

const refSpy = jest.fn();

render(
Expand All @@ -93,6 +100,7 @@ describe('integrations', () => {
<BoxWithShared />
<BoxWithSharedAndConditional />
<div className={css([shared, { background: 'cyan' }])} />
<BoxWithHas />
</div>
</ThemeContext.Provider>,
target
Expand All @@ -114,6 +122,7 @@ describe('integrations', () => {
'.go631307347{foo:1;color:red;baz:0;}',
'.go3865943372{opacity:0;}',
'.go1162430001{opacity:0;baz:0;}',
'.go2602823658 label:has(input, select),.go2602823658 :has(foo, boo){color:red;}',
'"'
].join('')
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export let parse = (obj, selector) => {
? // Go over the selector and replace the matching multiple selectors if any
selector.replace(/([^,])+/g, (sel) => {
// Return the current selector with the key matching multiple selectors if any
return key.replace(/(^:.*)|([^,])+/g, (k) => {
return key.replace(/([^,]*:\S+\([^)]*\))|([^,])+/g, (k) => {
// If the current `k`(key) has a nested selector replace it
if (/&/.test(k)) return k.replace(/&/g, sel);

Expand Down

0 comments on commit 907ee0c

Please sign in to comment.