Skip to content

Commit d89d5f3

Browse files
committed
[fixed] Modal error when backdrop is false
fixes react-bootstrap#1074
1 parent 7720d2c commit d89d5f3

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/Modal.js

+10
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,16 @@ const Modal = React.createClass({
226226
},
227227

228228
_setDialogRef(ref){
229+
// issue #1074
230+
// due to: https://github.com/facebook/react/blob/v0.13.3/src/core/ReactCompositeComponent.js#L842
231+
//
232+
// when backdrop is `false` react hasn't had a chance to reassign the refs to a usable object, b/c there are no other
233+
// "classic" refs on the component (or they haven't been processed yet)
234+
// TODO: Remove the need for this in next breaking release
235+
if (Object.isFrozen(this.refs) && !Object.keys(this.refs).length) {
236+
this.refs = {};
237+
}
238+
229239
this.refs.dialog = ref;
230240

231241
//maintains backwards compat with older component breakdown

test/ModalSpec.js

+11
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,17 @@ describe('Modal', function () {
160160
assert.match(dialog.props.className, /\btestCss\b/);
161161
});
162162

163+
it('Should assign refs correctly when no backdrop', function () {
164+
165+
let test = () => render(
166+
<Modal show backdrop={false} onHide={function () {}}>
167+
<strong>Message</strong>
168+
</Modal>
169+
, mountPoint);
170+
171+
expect(test).not.to.throw();
172+
});
173+
163174
it('Should pass transition callbacks to Transition', function (done) {
164175
let count = 0;
165176
let increment = ()=> count++;

0 commit comments

Comments
 (0)