From f1668bad15d27e6e2b40e5079f0b878603b33684 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Tue, 25 Apr 2017 12:34:21 -0400 Subject: Add confirm dialog before leaving private channel (#6206) --- webapp/components/confirm_modal.jsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'webapp/components/confirm_modal.jsx') diff --git a/webapp/components/confirm_modal.jsx b/webapp/components/confirm_modal.jsx index 8034caf9d..05288e3ac 100644 --- a/webapp/components/confirm_modal.jsx +++ b/webapp/components/confirm_modal.jsx @@ -10,11 +10,21 @@ export default class ConfirmModal extends React.Component { constructor(props) { super(props); - this.handleConfirm = this.handleConfirm.bind(this); + this.handleKeypress = this.handleKeypress.bind(this); } - handleConfirm() { - this.props.onConfirm(); + componentDidMount() { + document.addEventListener('keypress', this.handleKeypress); + } + + componentWillUnmount() { + document.removeEventListener('keypress', this.handleKeypress); + } + + handleKeypress(e) { + if (e.key === 'Enter' && this.props.show) { + this.props.onConfirm(); + } } render() { @@ -43,7 +53,7 @@ export default class ConfirmModal extends React.Component {