Skip to content

Commit

Permalink
[styles] Fix certain components not being considered mui elements
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Dec 13, 2018
1 parent 1bdd4a0 commit 7b48e00
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/material-ui-styles/src/hoistInternalStatics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* Copies internal immediate statics from material-ui from source to target
*/
export default function hoistStatics(target, source) {
const internals = ['muiName'];

for (let i = 0; i < internals.length; i += 1) {
const key = internals[i];
const descriptor = Object.getOwnPropertyDescriptor(source, key);
try {
// Avoid failures from read-only properties and undefined descriptors
Object.defineProperty(target, key, descriptor);
} catch (e) {}
}

return target;
}
3 changes: 3 additions & 0 deletions packages/material-ui-styles/src/withStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import mergeClasses from './mergeClasses';
import multiKeyStore from './multiKeyStore';
import getStylesCreator from './getStylesCreator';
import getThemeProps from './getThemeProps';
import hoistStatics from './hoistInternalStatics';
import { StylesContext } from './StylesProvider';
import { ThemeContext } from './ThemeProvider';

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

hoistStatics(WithStyles, Component);

if (process.env.NODE_ENV !== 'production') {
// Exposed for test purposes.
WithStyles.Naked = Component;
Expand Down
3 changes: 3 additions & 0 deletions packages/material-ui-styles/src/withTheme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';
import { getDisplayName } from '@material-ui/utils';
import hoistStatics from './hoistInternalStatics';
import { ThemeContext } from './ThemeProvider';

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

hoistStatics(WithTheme, Component);

return WithTheme;
};

Expand Down

0 comments on commit 7b48e00

Please sign in to comment.