diff options
Diffstat (limited to 'webapp/components/confirm_modal.jsx')
-rw-r--r-- | webapp/components/confirm_modal.jsx | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/webapp/components/confirm_modal.jsx b/webapp/components/confirm_modal.jsx index d6803499a..94f27a3e2 100644 --- a/webapp/components/confirm_modal.jsx +++ b/webapp/components/confirm_modal.jsx @@ -16,11 +16,23 @@ export default class ConfirmModal extends React.Component { } componentDidMount() { - document.addEventListener('keypress', this.handleKeypress); + if (this.props.show) { + document.addEventListener('keypress', this.handleKeypress); + } } componentWillUnmount() { - document.removeEventListener('keypress', this.handleKeypress); + if (!this.props.show) { + document.removeEventListener('keypress', this.handleKeypress); + } + } + + componentWillReceiveProps(nextProps) { + if (this.props.show && !nextProps.show) { + document.removeEventListener('keypress', this.handleKeypress); + } else if (!this.props.show && nextProps.show) { + document.addEventListener('keypress', this.handleKeypress); + } } handleKeypress(e) { |