diff options
| author | Oskar Nyberg <oskar@mullvad.net> | 2020-10-21 20:18:07 +0200 |
|---|---|---|
| committer | Oskar Nyberg <oskar@mullvad.net> | 2020-11-02 15:35:43 +0100 |
| commit | 3f08e1abb6c88277160c5049cf4a5fe644d223e0 (patch) | |
| tree | 1146508f1a8a63384a99c8311f90cc2c02f437b7 /gui/src | |
| parent | 5d690ccbb221c30902b89254707e5d0f44816d3d (diff) | |
| download | mullvadvpn-3f08e1abb6c88277160c5049cf4a5fe644d223e0.tar.xz mullvadvpn-3f08e1abb6c88277160c5049cf4a5fe644d223e0.zip | |
Make modal receive key event first and stop propagation
Diffstat (limited to 'gui/src')
| -rw-r--r-- | gui/src/renderer/components/Modal.tsx | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/gui/src/renderer/components/Modal.tsx b/gui/src/renderer/components/Modal.tsx index 4c449e8cf2..858c0be066 100644 --- a/gui/src/renderer/components/Modal.tsx +++ b/gui/src/renderer/components/Modal.tsx @@ -152,7 +152,9 @@ class ModalAlertWithContext extends React.Component<IModalAlertProps & IModalCon public componentDidMount() { this.props.setActiveModal(true); - document.addEventListener('keydown', this.handleKeyPress); + // The `true` argument specifies that the event should be dispatched in the capture phase. This + // makes sure that this component catches the event before the escape hatch. + document.addEventListener('keydown', this.handleKeyPress, true); const modalContainer = this.props.modalContainerRef.current; if (modalContainer) { @@ -170,7 +172,7 @@ class ModalAlertWithContext extends React.Component<IModalAlertProps & IModalCon public componentWillUnmount() { this.props.setActiveModal(false); - document.removeEventListener('keydown', this.handleKeyPress); + document.removeEventListener('keydown', this.handleKeyPress, true); this.appendScheduler.cancel(); this.props.modalContainerRef.current?.removeChild(this.element); @@ -219,6 +221,7 @@ class ModalAlertWithContext extends React.Component<IModalAlertProps & IModalCon private handleKeyPress = (event: KeyboardEvent) => { if (event.key === 'Escape') { + event.stopPropagation(); this.props.close?.(); } }; |
