Skip to content

Commit

Permalink
remove onRendered usage in the Popper component
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 19, 2019
1 parent dc82e61 commit 0a78aca
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions packages/material-ui/src/Popper/Popper.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import PopperJS from 'popper.js';
import { chainPropTypes } from '@material-ui/utils';
import Portal from '../Portal';
import { createChainedFunction } from '../utils/helpers';
import { useForkRef } from '../utils/reactHelpers';
import { setRef, useForkRef } from '../utils/reactHelpers';

/**
* Flips placement if in <body dir="rtl" />
Expand Down Expand Up @@ -58,7 +58,7 @@ const Popper = React.forwardRef(function Popper(props, ref) {
...other
} = props;
const tooltipRef = React.useRef(null);
const handleRef = useForkRef(tooltipRef, ref);
const ownRef = useForkRef(tooltipRef, ref);

const popperRef = React.useRef(null);
const handlePopperRefRef = React.useRef();
Expand All @@ -81,10 +81,6 @@ const Popper = React.forwardRef(function Popper(props, ref) {
}

const handleOpen = React.useCallback(() => {
const handlePopperUpdate = data => {
setPlacement(data.placement);
};

const popperNode = tooltipRef.current;

if (!popperNode || !anchorEl || !open) {
Expand All @@ -96,6 +92,10 @@ const Popper = React.forwardRef(function Popper(props, ref) {
handlePopperRefRef.current(null);
}

const handlePopperUpdate = data => {
setPlacement(data.placement);
};

const popper = new PopperJS(getAnchorEl(anchorEl), popperNode, {
placement: rtlPlacement,
...popperOptions,
Expand All @@ -118,6 +118,14 @@ const Popper = React.forwardRef(function Popper(props, ref) {
handlePopperRefRef.current(popper);
}, [anchorEl, disablePortal, modifiers, open, rtlPlacement, popperOptions]);

const handleRef = React.useCallback(
node => {
setRef(ownRef, node);
handleOpen();
},
[ownRef, handleOpen],
);

const handleEnter = () => {
setExited(false);
};
Expand Down Expand Up @@ -169,7 +177,7 @@ const Popper = React.forwardRef(function Popper(props, ref) {
}

return (
<Portal onRendered={handleOpen} disablePortal={disablePortal} container={container}>
<Portal disablePortal={disablePortal} container={container}>
<div
ref={handleRef}
role="tooltip"
Expand Down

0 comments on commit 0a78aca

Please sign in to comment.