Skip to content

Commit

Permalink
fix(merge-styles): Correctly processing selectors when value is a c…
Browse files Browse the repository at this point in the history
…lass name and they are not wrapped in `selectors` wrapper (#31798)
  • Loading branch information
khmakoto authored Jun 24, 2024
1 parent 9f13dee commit 1c0ba2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fix: Correctly processing selectors when value is a class name and they are not wrapped in 'selectors' wrapper.",
"packageName": "@fluentui/merge-styles",
"email": "[email protected]",
"dependentChangeType": "patch"
}
9 changes: 6 additions & 3 deletions packages/merge-styles/src/styleToClassName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ function expandCommaSeparatedGlobals(selectorWithGlobals: string): string {
}, selectorWithGlobals);
}

function isSelector(potentialSelector: string): boolean {
return potentialSelector.indexOf(':global(') >= 0 || potentialSelector.indexOf(':') === 0;
}

function expandSelector(newSelector: string, currentSelector: string): string {
if (newSelector.indexOf(':global(') >= 0) {
return newSelector.replace(globalSelectorRegExp, '$1');
Expand Down Expand Up @@ -138,7 +142,6 @@ function extractRules(
for (const prop in arg as any) {
if ((arg as any).hasOwnProperty(prop)) {
const propValue = (arg as any)[prop];

if (prop === 'selectors') {
// every child is a selector.
const selectors: { [key: string]: IStyle } = (arg as any).selectors;
Expand All @@ -148,9 +151,9 @@ function extractRules(
extractSelector(currentSelector, rules, newSelector, selectors[newSelector], stylesheet);
}
}
} else if (typeof propValue === 'object') {
} else if (typeof propValue === 'object' || isSelector(prop)) {
// prop is a selector.
if (propValue !== null) {
if (propValue !== null && propValue !== undefined) {
extractSelector(currentSelector, rules, prop, propValue, stylesheet);
}
} else {
Expand Down

0 comments on commit 1c0ba2f

Please sign in to comment.