Skip to content

Commit

Permalink
[core] Avoid test with instanceof HTMLElement
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Apr 19, 2020
1 parent 77f6fe0 commit 8918fce
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/material-ui/src/InputBase/InputBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ const InputBase = React.forwardRef(function InputBase(props, ref) {
const inputRef = React.useRef();
const handleInputRefWarning = React.useCallback((instance) => {
if (process.env.NODE_ENV !== 'production') {
if (instance && !(instance instanceof HTMLInputElement) && !instance.focus) {
if (instance && instance.nodeName !== 'INPUT' && !instance.focus) {
console.error(
[
'Material-UI: you have provided a `inputComponent` to the input component',
Expand Down
6 changes: 2 additions & 4 deletions packages/material-ui/src/Popover/Popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,10 @@ const Popover = React.forwardRef(function Popover(props, ref) {
}

const resolvedAnchorEl = getAnchorEl(anchorEl);
const containerWindow = ownerWindow(resolvedAnchorEl);

// If an anchor element wasn't provided, just use the parent body element of this Popover
const anchorElement =
resolvedAnchorEl instanceof containerWindow.Element
resolvedAnchorEl && resolvedAnchorEl.nodeType === 1
? resolvedAnchorEl
: ownerDocument(paperRef.current).body;
const anchorRect = anchorElement.getBoundingClientRect();
Expand Down Expand Up @@ -438,9 +437,8 @@ Popover.propTypes = {
anchorEl: chainPropTypes(PropTypes.oneOfType([PropTypes.object, PropTypes.func]), (props) => {
if (props.open && (!props.anchorReference || props.anchorReference === 'anchorEl')) {
const resolvedAnchorEl = getAnchorEl(props.anchorEl);
const containerWindow = ownerWindow(resolvedAnchorEl);

if (resolvedAnchorEl instanceof containerWindow.Element) {
if (resolvedAnchorEl && resolvedAnchorEl.nodeType === 1) {
const box = resolvedAnchorEl.getBoundingClientRect();

if (
Expand Down
8 changes: 2 additions & 6 deletions packages/material-ui/src/Popper/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import Portal from '../Portal';
import createChainedFunction from '../utils/createChainedFunction';
import setRef from '../utils/setRef';
import useForkRef from '../utils/useForkRef';
import ownerWindow from '../utils/ownerWindow';

function flipPlacement(placement, theme) {
const direction = (theme && theme.direction) || 'ltr';
Expand Down Expand Up @@ -101,9 +100,7 @@ const Popper = React.forwardRef(function Popper(props, ref) {
const resolvedAnchorEl = getAnchorEl(anchorEl);

if (process.env.NODE_ENV !== 'production') {
const containerWindow = ownerWindow(resolvedAnchorEl);

if (resolvedAnchorEl instanceof containerWindow.Element) {
if (resolvedAnchorEl && resolvedAnchorEl.nodeType === 1) {
const box = resolvedAnchorEl.getBoundingClientRect();

if (
Expand Down Expand Up @@ -243,9 +240,8 @@ Popper.propTypes = {
anchorEl: chainPropTypes(PropTypes.oneOfType([PropTypes.object, PropTypes.func]), (props) => {
if (props.open) {
const resolvedAnchorEl = getAnchorEl(props.anchorEl);
const containerWindow = ownerWindow(resolvedAnchorEl);

if (resolvedAnchorEl instanceof containerWindow.Element) {
if (resolvedAnchorEl && resolvedAnchorEl.nodeType === 1) {
const box = resolvedAnchorEl.getBoundingClientRect();

if (
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/test-utils/describeConformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function describeRef(element, getOptions) {
testRef(element, mount, (instance, wrapper) => {
assert.instanceOf(instance, refInstanceof);

if (inheritComponent && instance instanceof window.Element) {
if (inheritComponent && instance.nodeType === 1) {
const rootHost = findOutermostIntrinsic(wrapper);
assert.strictEqual(instance, rootHost.instance());
}
Expand Down
2 changes: 1 addition & 1 deletion packages/material-ui/src/utils/focusVisible.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ describe('focus-visible polyfill', () => {
simulatePointerDevice();

const { current: button } = buttonRef;
if (!(button instanceof window.HTMLButtonElement)) {
if (button.nodeName !== 'BUTTON') {
throw new Error('missing button');
}

Expand Down

0 comments on commit 8918fce

Please sign in to comment.