Skip to content

Commit 6c9e291

Browse files
[styles] Improve the dangerouslyUseGlobalCSS story
1 parent 8013fdd commit 6c9e291

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

packages/material-ui/src/styles/createGenerateClassName.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,13 @@ export default function createGenerateClassName(options = {}) {
5656

5757
// Code branch the whole block at the expense of more code.
5858
if (dangerouslyUseGlobalCSS) {
59-
if (styleSheet && styleSheet.options.classNamePrefix) {
60-
const prefix = safePrefix(styleSheet.options.classNamePrefix);
61-
62-
if (prefix.match(/^Mui/)) {
63-
return `${prefix}-${rule.key}`;
59+
if (styleSheet) {
60+
if (styleSheet.options.name) {
61+
return `${styleSheet.options.name}-${rule.key}`;
6462
}
6563

66-
if (process.env.NODE_ENV !== 'production') {
64+
if (styleSheet.options.classNamePrefix && process.env.NODE_ENV !== 'production') {
65+
const prefix = safePrefix(styleSheet.options.classNamePrefix);
6766
return `${prefix}-${rule.key}-${ruleCounter}`;
6867
}
6968
}

packages/material-ui/src/styles/createGenerateClassName.test.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,13 @@ describe('createGenerateClassName', () => {
5858
},
5959
{
6060
options: {
61-
classNamePrefix: 'MuiButton',
61+
name: 'Button',
62+
classNamePrefix: 'Button2',
6263
jss: {},
6364
},
6465
},
6566
),
66-
'MuiButton-root',
67+
'Button-root',
6768
);
6869
assert.strictEqual(
6970
generateClassName(

0 commit comments

Comments
 (0)