diff --git a/packages/material-ui/src/Popper/Popper.js b/packages/material-ui/src/Popper/Popper.js index 1e8f8d68a767eb..ce37362db8913f 100644 --- a/packages/material-ui/src/Popper/Popper.js +++ b/packages/material-ui/src/Popper/Popper.js @@ -66,23 +66,6 @@ class Popper extends React.Component { this.handleClose(); } - static getDerivedStateFromProps(nextProps) { - if (nextProps.open) { - return { - exited: false, - }; - } - - if (!nextProps.transition) { - // Otherwise let handleExited take care of marking exited. - return { - exited: true, - }; - } - - return null; - } - handleOpen = () => { const { anchorEl, modifiers, open, placement, popperOptions = {}, disablePortal } = this.props; const popperNode = this.tooltipRef.current; @@ -126,6 +109,10 @@ class Popper extends React.Component { } }; + handleEnter = () => { + this.setState({ exited: false }); + }; + handleExited = () => { this.setState({ exited: true }); this.handleClose(); @@ -173,6 +160,7 @@ class Popper extends React.Component { if (transition) { childProps.TransitionProps = { in: open, + onEnter: this.handleEnter, onExited: this.handleExited, }; } @@ -305,6 +293,7 @@ Popper.propTypes = { Popper.defaultProps = { disablePortal: false, + keepMounted: false, placement: 'bottom', transition: false, }; diff --git a/packages/material-ui/src/Popper/Popper.test.js b/packages/material-ui/src/Popper/Popper.test.js index cd5b1331f70983..06f2be0083f2c9 100644 --- a/packages/material-ui/src/Popper/Popper.test.js +++ b/packages/material-ui/src/Popper/Popper.test.js @@ -123,6 +123,49 @@ describe('', () => { }); }); + describe('prop: keepMounted', () => { + describe('by default', () => { + // Test case for https://github.com/mui-org/material-ui/issues/15180 + it('should remove the transition children in the DOM when closed whilst transition status is entering', () => { + const children =

Hello World

; + + class OpenClose extends React.Component { + state = { + open: false, + }; + + handleClick = () => { + this.setState({ open: true }, () => { + this.setState({ open: false }); + }); + }; + + render() { + return ( +
+ + + {({ TransitionProps }) => ( + + {children} + + )} + +
+ ); + } + } + + const wrapper = mount(); + assert.strictEqual(wrapper.contains(children), false); + wrapper.find('button').simulate('click'); + assert.strictEqual(wrapper.contains(children), false); + }); + }); + }); + describe('prop: transition', () => { it('should work', () => { const wrapper = mount( diff --git a/pages/api/popper.md b/pages/api/popper.md index 8bf70f7134d9f4..bb34348da6b909 100644 --- a/pages/api/popper.md +++ b/pages/api/popper.md @@ -22,7 +22,7 @@ Poppers rely on the 3rd party library [Popper.js](https://github.com/FezVrasta/p | children * | union: node |
 func
| | Popper render function or node. | | container | union: object |
 func
| | A node, component instance, or function that returns either. The `container` will passed to the Modal component. By default, it uses the body of the anchorEl's top-level document object, so it's simply `document.body` most of the time. | | disablePortal | bool | false | Disable the portal behavior. The children stay within it's parent DOM hierarchy. | -| keepMounted | bool | | Always keep the children in the DOM. This property can be useful in SEO situation or when you want to maximize the responsiveness of the Popper. | +| keepMounted | bool | false | Always keep the children in the DOM. This property can be useful in SEO situation or when you want to maximize the responsiveness of the Popper. | | modifiers | object | | Popper.js is based on a "plugin-like" architecture, most of its features are fully encapsulated "modifiers".
A modifier is a function that is called each time Popper.js needs to compute the position of the popper. For this reason, modifiers should be very performant to avoid bottlenecks. To learn how to create a modifier, [read the modifiers documentation](https://github.com/FezVrasta/popper.js/blob/master/docs/_includes/popper-documentation.md#modifiers--object). | | open * | bool | | If `true`, the popper is visible. | | placement | enum: 'bottom-end', 'bottom-start', 'bottom', 'left-end', 'left-start', 'left', 'right-end', 'right-start', 'right', 'top-end', 'top-start', 'top'
| 'bottom' | Popper placement. |