Skip to content

Commit 0f46a97

Browse files
jquenseJimmy Jia
authored and
Jimmy Jia
committedJul 30, 2015
[added] Allow custom Modal dialog components
1 parent 96ef53a commit 0f46a97

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed
 

‎src/Modal.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ import classNames from 'classnames';
44
import domUtils from './utils/domUtils';
55
import EventListener from './utils/EventListener';
66
import createChainedFunction from './utils/createChainedFunction';
7+
import CustomPropTypes from './utils/CustomPropTypes';
78

89
import Portal from './Portal';
910
import Fade from './Fade';
10-
import Dialog from './ModalDialog';
11+
import ModalDialog from './ModalDialog';
1112
import Body from './ModalBody';
1213
import Header from './ModalHeader';
1314
import Title from './ModalTitle';
@@ -94,7 +95,7 @@ function getScrollbarSize(){
9495
const Modal = React.createClass({
9596
propTypes: {
9697
...Portal.propTypes,
97-
...Dialog.propTypes,
98+
...ModalDialog.propTypes,
9899

99100
/**
100101
* Include a backdrop component. Specify 'static' for a backdrop that doesn't trigger an "onHide" when clicked.
@@ -110,6 +111,12 @@ const Modal = React.createClass({
110111
*/
111112
animation: React.PropTypes.bool,
112113

114+
/**
115+
* A Component type that provides the modal content Markup. This is a useful prop when you want to use your own
116+
* styles and markup to create a custom modal component.
117+
*/
118+
dialogComponent: CustomPropTypes.elementType,
119+
113120
/**
114121
* When `true` The modal will automatically shift focus to itself when it opens, and replace it to the last focused element when it closes.
115122
* Generally this should never be set to false as it makes the Modal less accessible to assistive technologies, like screen-readers.
@@ -127,6 +134,7 @@ const Modal = React.createClass({
127134
getDefaultProps(){
128135
return {
129136
bsClass: 'modal',
137+
dialogComponent: ModalDialog,
130138
show: false,
131139
animation: true,
132140
backdrop: true,
@@ -145,6 +153,7 @@ const Modal = React.createClass({
145153
let { onExit, onExiting, onEnter, onEntering, onEntered } = props;
146154

147155
let show = !!props.show;
156+
let Dialog = props.dialogComponent;
148157

149158
const mountModal = show || (animation && !this.state.exited);
150159
if (!mountModal) {
@@ -434,7 +443,7 @@ Modal.Header = Header;
434443
Modal.Title = Title;
435444
Modal.Footer = Footer;
436445

437-
Modal.Dialog = Dialog;
446+
Modal.Dialog = ModalDialog;
438447

439448
Modal.TRANSITION_DURATION = 300;
440449
Modal.BACKDROP_TRANSITION_DURATION = 150;

‎test/ModalSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,22 @@ describe('Modal', function () {
171171
expect(test).not.to.throw();
172172
});
173173

174+
it('Should use dialogComponent', function () {
175+
let noOp = function () {};
176+
177+
class CustomDialog {
178+
render(){ return <div {...this.props}/>; }
179+
}
180+
181+
let instance = render(
182+
<Modal show dialogComponent={CustomDialog} onHide={noOp}>
183+
<strong>Message</strong>
184+
</Modal>
185+
, mountPoint);
186+
187+
assert.ok(instance.refs.dialog instanceof CustomDialog);
188+
});
189+
174190
it('Should pass transition callbacks to Transition', function (done) {
175191
let count = 0;
176192
let increment = ()=> count++;

0 commit comments

Comments
 (0)