Skip to content

Commit a6dd179

Browse files
committed
Added the ability to decide whether the modal should be closed when clicking the overlay area.
This is an important ability since in some cases we don't want the modal to be closed when users are clicking outside.
1 parent 7f631bd commit a6dd179

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/components/Modal.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,16 @@ var Modal = module.exports = React.createClass({
2929
appElement: React.PropTypes.instanceOf(SafeHTMLElement),
3030
onRequestClose: React.PropTypes.func,
3131
closeTimeoutMS: React.PropTypes.number,
32-
ariaHideApp: React.PropTypes.bool
32+
ariaHideApp: React.PropTypes.bool,
33+
shouldCloseOnOverlayClick: React.PropTypes.bool
3334
},
3435

3536
getDefaultProps: function () {
3637
return {
3738
isOpen: false,
3839
ariaHideApp: true,
39-
closeTimeoutMS: 0
40+
closeTimeoutMS: 0,
41+
shouldCloseOnOverlayClick: true
4042
};
4143
},
4244

lib/components/ModalPortal.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ var ModalPortal = module.exports = React.createClass({
146146
},
147147

148148
handleOverlayClick: function() {
149-
if (this.ownerHandlesClose())
150-
this.requestClose();
151-
else
152-
this.focusContent();
149+
if (this.props.shouldCloseOnOverlayClick) {
150+
if (this.ownerHandlesClose())
151+
this.requestClose();
152+
else
153+
this.focusContent();
154+
}
153155
},
154156

155157
requestClose: function() {

0 commit comments

Comments
 (0)