Skip to content

Commit

Permalink
fix: prevent mouse event when shouldCloseOnOverlayClick = false.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
diasbruno committed Nov 23, 2017
1 parent cba31dd commit a296627
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
1 change: 1 addition & 0 deletions examples/basic/simple_usage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)}>
<h1 id="heading" ref={h1 => this.heading = h1}>This is the modal 2!</h1>
Expand Down
5 changes: 4 additions & 1 deletion src/components/ModalPortal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit a296627

Please sign in to comment.