Skip to content

Commit ccd990a

Browse files
committed
[styles] Fix certain components not being considered mui elements
1 parent 1bdd4a0 commit ccd990a

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.size-limit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ module.exports = [
4141
name: 'The main docs bundle',
4242
webpack: false,
4343
path: main.path,
44-
limit: '176 KB',
44+
limit: '176.1 KB',
4545
},
4646
{
4747
name: 'The docs home page',
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/**
2+
* Copies internal immediate statics from material-ui from source to target
3+
*/
4+
export default function hoistStatics(target, source) {
5+
const internals = ['muiName'];
6+
7+
for (let i = 0; i < internals.length; i += 1) {
8+
const key = internals[i];
9+
const descriptor = Object.getOwnPropertyDescriptor(source, key);
10+
try {
11+
Object.defineProperty(target, key, descriptor);
12+
} catch (e) {
13+
// Avoid failures from read-only properties and undefined descriptors
14+
}
15+
}
16+
17+
return target;
18+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import mergeClasses from './mergeClasses';
88
import multiKeyStore from './multiKeyStore';
99
import getStylesCreator from './getStylesCreator';
1010
import getThemeProps from './getThemeProps';
11+
import hoistStatics from './hoistInternalStatics';
1112
import { StylesContext } from './StylesProvider';
1213
import { ThemeContext } from './ThemeProvider';
1314

@@ -332,6 +333,8 @@ const withStyles = (stylesOrCreator, options = {}) => Component => {
332333
WithStyles.displayName = `WithStyles(${getDisplayName(Component)})`;
333334
}
334335

336+
hoistStatics(WithStyles, Component);
337+
335338
if (process.env.NODE_ENV !== 'production') {
336339
// Exposed for test purposes.
337340
WithStyles.Naked = Component;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { getDisplayName } from '@material-ui/utils';
4+
import hoistStatics from './hoistInternalStatics';
45
import { ThemeContext } from './ThemeProvider';
56

67
// Provide the theme object as a property to the input component.
@@ -25,6 +26,8 @@ const withTheme = () => Component => {
2526
WithTheme.displayName = `WithTheme(${getDisplayName(Component)})`;
2627
}
2728

29+
hoistStatics(WithTheme, Component);
30+
2831
return WithTheme;
2932
};
3033

0 commit comments

Comments
 (0)