From bec3360b6650b720354693be0b46cc0ae3f17245 Mon Sep 17 00:00:00 2001 From: Developer <> Date: Thu, 18 Feb 2021 17:22:11 -0500 Subject: [PATCH] Added checks in ModalBase, PopoverBase if page goes back/forward to dismiss MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Added: - checks in ModalBase, PopoverBase if page goes back/forward (popstate) to dismiss the modal, popover --- app/javascript/gabsocial/components/modal/modal_base.js | 6 ++++-- app/javascript/gabsocial/components/popover/popover_base.js | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/javascript/gabsocial/components/modal/modal_base.js b/app/javascript/gabsocial/components/modal/modal_base.js index 3a1b2de5..22bc0dd1 100644 --- a/app/javascript/gabsocial/components/modal/modal_base.js +++ b/app/javascript/gabsocial/components/modal/modal_base.js @@ -23,10 +23,10 @@ class ModalBase extends React.PureComponent { } } - handleOnClose = (e) => { + handleOnClose = (e, force) => { const { onOpenModal, composeText, composeId, onClose, intl, type, onCancelReplyCompose } = this.props - if (!!e && this.dialog !== e.target) return + if ((!!e && this.dialog !== e.target) && !force) return if (!composeId && composeText && type === 'COMPOSE') { onOpenModal('CONFIRM', { @@ -42,6 +42,7 @@ class ModalBase extends React.PureComponent { componentDidMount() { window.addEventListener('keyup', this.handleKeyUp, false) + window.addEventListener('popstate', (e) => this.handleOnClose(e, true), false); } componentWillReceiveProps(nextProps) { @@ -73,6 +74,7 @@ class ModalBase extends React.PureComponent { componentWillUnmount() { window.removeEventListener('keyup', this.handleKeyUp) + window.removeEventListener('popstate', this.handleOnClose, false); } getSiblings = () => { diff --git a/app/javascript/gabsocial/components/popover/popover_base.js b/app/javascript/gabsocial/components/popover/popover_base.js index 4dc21e52..9c9624bf 100644 --- a/app/javascript/gabsocial/components/popover/popover_base.js +++ b/app/javascript/gabsocial/components/popover/popover_base.js @@ -19,12 +19,14 @@ class PopoverBase extends ImmutablePureComponent { document.addEventListener('click', this.handleDocumentClick, false) document.addEventListener('keydown', this.handleKeyDown, false) document.addEventListener('touchend', this.handleDocumentClick, listenerOptions) + window.addEventListener('popstate', this.handleClose, false); } componentWillUnmount() { document.removeEventListener('click', this.handleDocumentClick, false) document.removeEventListener('keydown', this.handleKeyDown, false) document.removeEventListener('touchend', this.handleDocumentClick, listenerOptions) + window.removeEventListener('hashchange', this.handleClose); } handleDocumentClick = (e) => {