diff --git a/src/Popover/Popover.js b/src/Popover/Popover.js index a52d7918fbd87e..cbae81c9d25de2 100644 --- a/src/Popover/Popover.js +++ b/src/Popover/Popover.js @@ -159,6 +159,9 @@ class Popover extends Component { } componentWillUnmount() { + this.handleResize.cancel(); + this.handleScroll.cancel(); + if (this.timeout) { clearTimeout(this.timeout); this.timeout = null; @@ -206,10 +209,6 @@ class Popover extends Component { this.requestClose('clickAway'); }; - _resizeAutoPosition() { - this.setPlacement(); - } - getAnchorPosition(el) { if (!el) { el = ReactDOM.findDOMNode(this); @@ -247,8 +246,6 @@ class Popover extends Component { return; } - const anchorEl = this.props.anchorEl || this.anchorEl; - if (!this.refs.layer.getLayer()) { return; } @@ -259,6 +256,7 @@ class Popover extends Component { } const {targetOrigin, anchorOrigin} = this.props; + const anchorEl = this.props.anchorEl || this.anchorEl; const anchor = this.getAnchorPosition(anchorEl); let target = this.getTargetPosition(targetEl); diff --git a/src/Popover/Popover.spec.js b/src/Popover/Popover.spec.js index 817ee7fdadd9cc..b612fd2907d4e4 100644 --- a/src/Popover/Popover.spec.js +++ b/src/Popover/Popover.spec.js @@ -2,13 +2,14 @@ import React from 'react'; import {assert} from 'chai'; -import {shallow} from 'enzyme'; +import {shallow, mount} from 'enzyme'; import Popover from './Popover'; import getMuiTheme from '../styles/getMuiTheme'; describe('', () => { const muiTheme = getMuiTheme(); const shallowWithContext = (node) => shallow(node, {context: {muiTheme}}); + const mountWithContext = (node) => mount(node, {context: {muiTheme}}); describe('state: closing', () => { it('should not create new timeout when popover is already closing', () => { @@ -23,4 +24,19 @@ describe('', () => { assert.strictEqual(timeout, nextTimeout); }); }); + + describe('unmounting', () => { + it('should stop listening correctly', (done) => { + const wrapper = mountWithContext(); + + wrapper.instance().handleScroll(); + wrapper.instance().handleScroll(); + wrapper.unmount(); + + setTimeout(() => { + // Wait for the end of the throttle. Makes sure we don't crash. + done(); + }, 100); + }); + }); });