Skip to content

Commit a296627

Browse files
committed
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.
1 parent cba31dd commit a296627

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

examples/basic/simple_usage/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ class SimpleUsage extends Component {
7676
closeTimeoutMS={150}
7777
contentLabel="modalB"
7878
isOpen={currentModal == MODAL_B}
79+
shouldCloseOnOverlayClick={false}
7980
onAfterOpen={this.handleOnAfterOpenModal}
8081
onRequestClose={this.toggleModal(MODAL_B)}>
8182
<h1 id="heading" ref={h1 => this.heading = h1}>This is the modal 2!</h1>

src/components/ModalPortal.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,10 @@ export default class ModalPortal extends Component {
242242
this.shouldClose = false;
243243
};
244244

245-
handleOverlayOnMouseDown = () => {
245+
handleOverlayOnMouseDown = event => {
246+
if (!this.props.shouldCloseOnOverlayClick) {
247+
event.preventDefault();
248+
}
246249
this.moveFromContentToOverlay = false;
247250
};
248251

0 commit comments

Comments
 (0)