Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(fix) Fixes the :has and other selector when used with multiple (fixes #596) #597

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading