Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[added] ability to change default 'ReactModalPortal' class #208

Merged
merged 1 commit into from
Aug 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ you can pass `className` and `overlayClassName` props to the Modal. If you do
this then none of the default styles will apply and you will have full control
over styling via CSS.

You can also pass a `portalClassName` to change the wrapper's class (*ReactModalPortal*).
This doesn't affect styling as no styles are applied to this element by default.

### Overriding styles globally
The default styles above are available on `Modal.defaultStyles`. Changes to this
Expand Down
4 changes: 3 additions & 1 deletion lib/components/Modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var Modal = React.createClass({
content: React.PropTypes.object,
overlay: React.PropTypes.object
}),
portalClassName: React.PropTypes.string,
appElement: React.PropTypes.instanceOf(SafeHTMLElement),
onAfterOpen: React.PropTypes.func,
onRequestClose: React.PropTypes.func,
Expand All @@ -41,6 +42,7 @@ var Modal = React.createClass({
getDefaultProps: function () {
return {
isOpen: false,
portalClassName: 'ReactModalPortal',
ariaHideApp: true,
closeTimeoutMS: 0,
shouldCloseOnOverlayClick: true
Expand All @@ -49,7 +51,7 @@ var Modal = React.createClass({

componentDidMount: function() {
this.node = document.createElement('div');
this.node.className = 'ReactModalPortal';
this.node.className = this.props.portalClassName;
document.body.appendChild(this.node);
this.renderPortal(this.props);
},
Expand Down
6 changes: 6 additions & 0 deletions specs/Modal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ describe('Modal', function () {
equal(tabPrevented, true);
});

it('supports portalClassName', function () {
var modal = renderModal({isOpen: true, portalClassName: 'myPortalClass'});
equal(modal.node.className, 'myPortalClass');
unmountModal();
});

it('supports custom className', function() {
var modal = renderModal({isOpen: true, className: 'myClass'});
notEqual(modal.portal.refs.content.className.indexOf('myClass'), -1);
Expand Down