diff --git a/lib/portal.js b/lib/portal.js index 6497991..c4fcf66 100644 --- a/lib/portal.js +++ b/lib/portal.js @@ -9,7 +9,6 @@ export default class Portal extends React.Component { constructor() { super(); - this.state = { active: false }; this.handleWrapperClick = this.handleWrapperClick.bind(this); this.closePortal = this.closePortal.bind(this); this.handleOutsideMouseClick = this.handleOutsideMouseClick.bind(this); @@ -37,19 +36,19 @@ export default class Portal extends React.Component { // portal's 'is open' state is handled through the prop isOpen if (typeof newProps.isOpen !== 'undefined') { if (newProps.isOpen) { - if (this.state.active) { + if (this.active) { this.renderPortal(newProps); } else { this.openPortal(newProps); } } - if (!newProps.isOpen && this.state.active) { + if (!newProps.isOpen && this.active) { this.closePortal(); } } // portal handles its own 'is open' state - if (typeof newProps.isOpen === 'undefined' && this.state.active) { + if (typeof newProps.isOpen === 'undefined' && this.active) { this.renderPortal(newProps); } } @@ -70,12 +69,12 @@ export default class Portal extends React.Component { handleWrapperClick(e) { e.preventDefault(); e.stopPropagation(); - if (this.state.active) { return; } + if (this.active) { return; } this.openPortal(); } openPortal(props = this.props) { - this.setState({ active: true }); + this.active = true; this.renderPortal(props, true); } @@ -88,11 +87,11 @@ export default class Portal extends React.Component { this.portal = null; this.node = null; if (isUnmounted !== true) { - this.setState({ active: false }); + this.active = false; } }; - if (this.state.active) { + if (this.active) { if (this.props.beforeClose) { this.props.beforeClose(this.node, resetPortalState); } else { @@ -104,7 +103,7 @@ export default class Portal extends React.Component { } handleOutsideMouseClick(e) { - if (!this.state.active) { return; } + if (!this.active) { return; } const root = findDOMNode(this.portal); if (root.contains(e.target) || (e.button && e.button !== 0)) { return; } @@ -114,7 +113,7 @@ export default class Portal extends React.Component { } handleKeydown(e) { - if (e.keyCode === KEYCODES.ESCAPE && this.state.active) { + if (e.keyCode === KEYCODES.ESCAPE && this.active) { this.closePortal(); } }