From 8eeec3232cc0e5f004fd7aa34df9027cff474cb0 Mon Sep 17 00:00:00 2001 From: Zain Gulbaz Date: Sun, 21 Aug 2022 09:54:45 +0500 Subject: [PATCH 1/2] [Added] Modal close on righlt click on overlay --- src/components/ModalPortal.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/components/ModalPortal.js b/src/components/ModalPortal.js index 35e9837e..d04d52f9 100644 --- a/src/components/ModalPortal.js +++ b/src/components/ModalPortal.js @@ -299,6 +299,16 @@ export default class ModalPortal extends Component { this.shouldClose = null; }; + handleOverlayOnContextMenu = event => { + if(this.shouldClose===null)this.shouldClose=true; + else if(!this.shouldClose) this.shouldClose=null; + if(this.shouldClose) + { + event.preventDefault(); + this.requestClose(event); + } + }; + handleContentOnMouseUp = () => { this.shouldClose = false; }; @@ -375,7 +385,8 @@ export default class ModalPortal extends Component { className: this.buildClassName("overlay", overlayClassName), style: { ...overlayStyles, ...this.props.style.overlay }, onClick: this.handleOverlayOnClick, - onMouseDown: this.handleOverlayOnMouseDown + onMouseDown: this.handleOverlayOnMouseDown, + onContextMenu: this.handleOverlayOnContextMenu, }; const contentProps = { From 2d55831d8955dcb2a2a65a7cb5b0efe84397c2fa Mon Sep 17 00:00:00 2001 From: Zain Gulbaz Date: Sun, 21 Aug 2022 10:43:25 +0500 Subject: [PATCH 2/2] [Added] Modal close on righlt click on overlay --- docs/index.md | 4 ++++ src/components/Modal.js | 2 ++ src/components/ModalPortal.js | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 4e8a296e..dd5b2cb9 100644 --- a/docs/index.md +++ b/docs/index.md @@ -115,6 +115,10 @@ import ReactModal from 'react-modal'; true /* Boolean indicating if the overlay should close the modal */} + shouldCloseOnOverlayRightClick={ + true + /* Boolean indicating if the overlay should close the modal on right click*/} + shouldCloseOnEsc={ true /* Boolean indicating if pressing the esc key should close the modal diff --git a/src/components/Modal.js b/src/components/Modal.js index c064b213..fbfb4e26 100644 --- a/src/components/Modal.js +++ b/src/components/Modal.js @@ -70,6 +70,7 @@ class Modal extends Component { ariaHideApp: PropTypes.bool, shouldFocusAfterRender: PropTypes.bool, shouldCloseOnOverlayClick: PropTypes.bool, + shouldCloseOnOverlayRightClick:PropTypes.bool, shouldReturnFocusAfterClose: PropTypes.bool, preventScroll: PropTypes.bool, parentSelector: PropTypes.func, @@ -96,6 +97,7 @@ class Modal extends Component { shouldFocusAfterRender: true, shouldCloseOnEsc: true, shouldCloseOnOverlayClick: true, + shouldCloseOnOverlayRightClick:false, shouldReturnFocusAfterClose: true, preventScroll: false, parentSelector: () => document.body, diff --git a/src/components/ModalPortal.js b/src/components/ModalPortal.js index d04d52f9..acfa8467 100644 --- a/src/components/ModalPortal.js +++ b/src/components/ModalPortal.js @@ -302,7 +302,7 @@ export default class ModalPortal extends Component { handleOverlayOnContextMenu = event => { if(this.shouldClose===null)this.shouldClose=true; else if(!this.shouldClose) this.shouldClose=null; - if(this.shouldClose) + if(this.shouldClose && this.props.shouldCloseOnOverlayRightClick) { event.preventDefault(); this.requestClose(event);