Skip to content

Commit 596f40c

Browse files
committed
[fixed] Modal uses bsClass prop to set its classes
1 parent 58eaab0 commit 596f40c

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/Modal.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ const Modal = React.createClass({
126126

127127
getDefaultProps(){
128128
return {
129+
bsClass: 'modal',
129130
show: false,
130131
animation: true,
131132
backdrop: true,
@@ -203,12 +204,12 @@ const Modal = React.createClass({
203204
},
204205

205206
renderBackdrop(modal) {
206-
let { animation } = this.props;
207+
let { animation, bsClass } = this.props;
207208
let duration = Modal.BACKDROP_TRANSITION_DURATION;
208209

209210
let backdrop = (
210211
<div ref="backdrop"
211-
className={classNames('modal-backdrop', { in: this.props.show && !animation })}
212+
className={classNames(`${bsClass}-backdrop`, { in: this.props.show && !animation })}
212213
onClick={this.handleBackdropClick}
213214
/>
214215
);

src/ModalDialog.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ const ModalDialog = React.createClass({
3232

3333
render() {
3434
let modalStyle = { display: 'block'};
35+
let bsClass = this.props.bsClass;
3536
let dialogClasses = this.getBsClassSet();
3637

3738
delete dialogClasses.modal;
38-
dialogClasses['modal-dialog'] = true;
39+
dialogClasses[`${bsClass}-dialog`] = true;
3940

4041
return (
4142
<div
@@ -44,10 +45,10 @@ const ModalDialog = React.createClass({
4445
tabIndex="-1"
4546
role="dialog"
4647
style={modalStyle}
47-
className={classNames(this.props.className, 'modal')}
48+
className={classNames(this.props.className, bsClass)}
4849
>
4950
<div className={classNames(this.props.dialogClassName, dialogClasses)}>
50-
<div className="modal-content" role='document'>
51+
<div className={`${bsClass}-content`} role='document'>
5152
{ this.props.children }
5253
</div>
5354
</div>

test/ModalSpec.js

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import ReactTestUtils from 'react/lib/ReactTestUtils';
33
import Modal from '../src/Modal';
4-
import { render } from './helpers';
4+
import { render, shouldWarn } from './helpers';
55

66
describe('Modal', function () {
77
let mountPoint;
@@ -115,6 +115,27 @@ describe('Modal', function () {
115115
ReactTestUtils.Simulate.click(button);
116116
});
117117

118+
it('Should use bsClass on the dialog', function () {
119+
let noOp = function () {};
120+
let instance = render(
121+
<Modal show bsClass='mymodal' onHide={noOp}>
122+
<strong>Message</strong>
123+
</Modal>
124+
, mountPoint);
125+
126+
let dialog = React.findDOMNode(instance.refs.dialog);
127+
let backdrop = React.findDOMNode(instance.refs.backdrop);
128+
129+
assert.ok(dialog.className.match(/\bmymodal\b/));
130+
assert.ok(dialog.children[0].className.match(/\bmymodal-dialog\b/));
131+
assert.ok(dialog.children[0].children[0].className.match(/\bmymodal-content\b/));
132+
133+
assert.ok(backdrop.className.match(/\bmymodal-backdrop\b/));
134+
135+
136+
shouldWarn("Invalid prop 'bsClass' of value 'mymodal'");
137+
});
138+
118139
it('Should pass bsSize to the dialog', function () {
119140
let noOp = function () {};
120141
let instance = render(

0 commit comments

Comments
 (0)