diff --git a/src/Modal.js b/src/Modal.js
index a6a5b20df1..bcd6c2db7e 100644
--- a/src/Modal.js
+++ b/src/Modal.js
@@ -269,9 +269,12 @@ const Modal = React.createClass({
},
focusModalContent () {
- this.lastFocus = domUtils.activeElement(this);
- let modalContent = React.findDOMNode(this.refs.modal);
- modalContent.focus();
+ if (this.props.enforceFocus) {
+ this.lastFocus = domUtils.activeElement(this);
+
+ let modalContent = React.findDOMNode(this.refs.modal);
+ modalContent.focus();
+ }
},
restoreLastFocus () {
diff --git a/test/ModalSpec.js b/test/ModalSpec.js
index e81209d9e1..0e516d52dc 100644
--- a/test/ModalSpec.js
+++ b/test/ModalSpec.js
@@ -156,6 +156,36 @@ describe('Modal', function () {
}, 0);
});
+ it('Should not focus on the Modal when enforceFocus is false', function (done) {
+
+ document.activeElement.should.equal(focusableContainer);
+
+ let Container = React.createClass({
+ getInitialState() {
+ return {modalOpen: true};
+ },
+ render() {
+ if (this.state.modalOpen) {
+ return (
+ {}} container={this}>
+ Message
+
+ );
+ } else {
+ return ;
+ }
+ }
+ });
+
+ React.render(, focusableContainer);
+
+ setTimeout(function () {
+ // modal should be focused when opened
+ document.activeElement.should.equal(focusableContainer);
+ done();
+ }, 0);
+ });
});
+
});