From a2966274747a8a46e12e5c626eb19b7cc7444ce1 Mon Sep 17 00:00:00 2001 From: Bruno Dias Date: Thu, 23 Nov 2017 10:05:10 -0300 Subject: [PATCH] fix: prevent mouse event when shouldCloseOnOverlayClick = false. This is tricky, if the user don't allow close when clicking on the overlay, we need to stop the event so the focus won't leave the modal (where the key handler is defined). closes #186. --- examples/basic/simple_usage/index.js | 1 + src/components/ModalPortal.js | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/basic/simple_usage/index.js b/examples/basic/simple_usage/index.js index c675927f..4ab6676d 100644 --- a/examples/basic/simple_usage/index.js +++ b/examples/basic/simple_usage/index.js @@ -76,6 +76,7 @@ class SimpleUsage extends Component { closeTimeoutMS={150} contentLabel="modalB" isOpen={currentModal == MODAL_B} + shouldCloseOnOverlayClick={false} onAfterOpen={this.handleOnAfterOpenModal} onRequestClose={this.toggleModal(MODAL_B)}>

this.heading = h1}>This is the modal 2!

diff --git a/src/components/ModalPortal.js b/src/components/ModalPortal.js index 823d3681..bf5d25f5 100644 --- a/src/components/ModalPortal.js +++ b/src/components/ModalPortal.js @@ -242,7 +242,10 @@ export default class ModalPortal extends Component { this.shouldClose = false; }; - handleOverlayOnMouseDown = () => { + handleOverlayOnMouseDown = event => { + if (!this.props.shouldCloseOnOverlayClick) { + event.preventDefault(); + } this.moveFromContentToOverlay = false; };