Skip to content

Commit df44a7c

Browse files
add HTMLElementType
1 parent 8918fce commit df44a7c

File tree

6 files changed

+35
-7
lines changed

6 files changed

+35
-7
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
export default function HTMLElementType(props, propName, componentName, location, propFullName) {
2+
if (process.env.NODE_ENV === 'production') {
3+
return null;
4+
}
5+
6+
const propValue = props[propName];
7+
const safePropName = propFullName || propName;
8+
9+
if (propValue == null) {
10+
return null;
11+
}
12+
13+
if (propValue && propValue.nodeType !== 1) {
14+
return new Error(
15+
`Invalid ${location} \`${safePropName}\` supplied to \`${componentName}\`. ` +
16+
`Expected an HTMLElement.`,
17+
);
18+
}
19+
20+
return null;
21+
}

packages/material-ui-utils/src/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ export { default as elementAcceptingRef } from './elementAcceptingRef';
44
export { default as elementTypeAcceptingRef } from './elementTypeAcceptingRef';
55
export { default as exactProp } from './exactProp';
66
export { default as getDisplayName } from './getDisplayName';
7+
export { default as HTMLElementType } from './HTMLElementType';
78
export { default as ponyfillGlobal } from './ponyfillGlobal';
89
export { default as refType } from './refType';

packages/material-ui/src/Menu/Menu.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as React from 'react';
22
import { isFragment } from 'react-is';
33
import PropTypes from 'prop-types';
44
import clsx from 'clsx';
5+
import { HTMLElementType } from '@material-ui/utils';
56
import withStyles from '../styles/withStyles';
67
import Popover from '../Popover';
78
import MenuList from '../MenuList';
@@ -175,7 +176,7 @@ Menu.propTypes = {
175176
*/
176177
anchorEl: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
177178
PropTypes.func,
178-
PropTypes.instanceOf(typeof Element === 'undefined' ? Object : Element),
179+
HTMLElementType,
179180
]),
180181
/**
181182
* If `true` (Default) will focus the `[role="menu"]` if no focusable child is found. Disabled

packages/material-ui/src/Popover/Popover.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
import * as React from 'react';
22
import PropTypes from 'prop-types';
33
import * as ReactDOM from 'react-dom';
4+
import {
5+
chainPropTypes,
6+
elementTypeAcceptingRef,
7+
refType,
8+
HTMLElementType,
9+
} from '@material-ui/utils';
410
import debounce from '../utils/debounce';
511
import clsx from 'clsx';
6-
import { chainPropTypes, elementTypeAcceptingRef, refType } from '@material-ui/utils';
712
import ownerDocument from '../utils/ownerDocument';
813
import ownerWindow from '../utils/ownerWindow';
914
import createChainedFunction from '../utils/createChainedFunction';
@@ -522,7 +527,7 @@ Popover.propTypes = {
522527
container: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
523528
PropTypes.func,
524529
PropTypes.instanceOf(React.Component),
525-
PropTypes.instanceOf(typeof Element === 'undefined' ? Object : Element),
530+
HTMLElementType,
526531
]),
527532
/**
528533
* The elevation of the popover.

packages/material-ui/src/Popper/Popper.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import PropTypes from 'prop-types';
33
import PopperJs from 'popper.js';
4-
import { chainPropTypes, refType } from '@material-ui/utils';
4+
import { chainPropTypes, refType, HTMLElementType } from '@material-ui/utils';
55
import { useTheme } from '@material-ui/styles';
66
import Portal from '../Portal';
77
import createChainedFunction from '../utils/createChainedFunction';
@@ -293,7 +293,7 @@ Popper.propTypes = {
293293
container: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
294294
PropTypes.func,
295295
PropTypes.instanceOf(React.Component),
296-
PropTypes.instanceOf(typeof Element === 'undefined' ? Object : Element),
296+
HTMLElementType,
297297
]),
298298
/**
299299
* Disable the portal behavior.

packages/material-ui/src/Portal/Portal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import * as ReactDOM from 'react-dom';
33
import PropTypes from 'prop-types';
4-
import { exactProp } from '@material-ui/utils';
4+
import { exactProp, HTMLElementType } from '@material-ui/utils';
55
import setRef from '../utils/setRef';
66
import useForkRef from '../utils/useForkRef';
77

@@ -75,7 +75,7 @@ Portal.propTypes = {
7575
container: PropTypes /* @typescript-to-proptypes-ignore */.oneOfType([
7676
PropTypes.func,
7777
PropTypes.instanceOf(React.Component),
78-
PropTypes.instanceOf(typeof Element === 'undefined' ? Object : Element),
78+
HTMLElementType,
7979
]),
8080
/**
8181
* Disable the portal behavior.

0 commit comments

Comments
 (0)