Skip to content

Commit

Permalink
[added] Allow custom Modal dialog components
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense authored and Jimmy Jia committed Jul 30, 2015
1 parent 96ef53a commit 0f46a97
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import classNames from 'classnames';
import domUtils from './utils/domUtils';
import EventListener from './utils/EventListener';
import createChainedFunction from './utils/createChainedFunction';
import CustomPropTypes from './utils/CustomPropTypes';

import Portal from './Portal';
import Fade from './Fade';
import Dialog from './ModalDialog';
import ModalDialog from './ModalDialog';
import Body from './ModalBody';
import Header from './ModalHeader';
import Title from './ModalTitle';
Expand Down Expand Up @@ -94,7 +95,7 @@ function getScrollbarSize(){
const Modal = React.createClass({
propTypes: {
...Portal.propTypes,
...Dialog.propTypes,
...ModalDialog.propTypes,

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

/**
* A Component type that provides the modal content Markup. This is a useful prop when you want to use your own
* styles and markup to create a custom modal component.
*/
dialogComponent: CustomPropTypes.elementType,

/**
* When `true` The modal will automatically shift focus to itself when it opens, and replace it to the last focused element when it closes.
* Generally this should never be set to false as it makes the Modal less accessible to assistive technologies, like screen-readers.
Expand All @@ -127,6 +134,7 @@ const Modal = React.createClass({
getDefaultProps(){
return {
bsClass: 'modal',
dialogComponent: ModalDialog,
show: false,
animation: true,
backdrop: true,
Expand All @@ -145,6 +153,7 @@ const Modal = React.createClass({
let { onExit, onExiting, onEnter, onEntering, onEntered } = props;

let show = !!props.show;
let Dialog = props.dialogComponent;

const mountModal = show || (animation && !this.state.exited);
if (!mountModal) {
Expand Down Expand Up @@ -434,7 +443,7 @@ Modal.Header = Header;
Modal.Title = Title;
Modal.Footer = Footer;

Modal.Dialog = Dialog;
Modal.Dialog = ModalDialog;

Modal.TRANSITION_DURATION = 300;
Modal.BACKDROP_TRANSITION_DURATION = 150;
Expand Down
16 changes: 16 additions & 0 deletions test/ModalSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,22 @@ describe('Modal', function () {
expect(test).not.to.throw();
});

it('Should use dialogComponent', function () {
let noOp = function () {};

class CustomDialog {
render(){ return <div {...this.props}/>; }
}

let instance = render(
<Modal show dialogComponent={CustomDialog} onHide={noOp}>
<strong>Message</strong>
</Modal>
, mountPoint);

assert.ok(instance.refs.dialog instanceof CustomDialog);
});

it('Should pass transition callbacks to Transition', function (done) {
let count = 0;
let increment = ()=> count++;
Expand Down

0 comments on commit 0f46a97

Please sign in to comment.