Skip to content

Commit bc58b9c

Browse files
committed
Merge pull request #100 from claydiffrient/bugfix/classes-take-precedence
[fixed] Custom classnames override default styles
2 parents 7f631bd + 63bee72 commit bc58b9c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lib/components/ModalPortal.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -175,16 +175,19 @@ var ModalPortal = module.exports = React.createClass({
175175
},
176176

177177
render: function() {
178+
var contentStyles = (this.props.className) ? {} : defaultStyles.content;
179+
var overlayStyles = (this.props.overlayClassName) ? {} : defaultStyles.overlay;
180+
178181
return this.shouldBeClosed() ? div() : (
179182
div({
180183
ref: "overlay",
181184
className: this.buildClassName('overlay', this.props.overlayClassName),
182-
style: Assign({}, defaultStyles.overlay, this.props.style.overlay || {}),
185+
style: Assign({}, overlayStyles, this.props.style.overlay || {}),
183186
onClick: this.handleOverlayClick
184187
},
185188
div({
186189
ref: "content",
187-
style: Assign({}, defaultStyles.content, this.props.style.content || {}),
190+
style: Assign({}, contentStyles, this.props.style.content || {}),
188191
className: this.buildClassName('content', this.props.className),
189192
tabIndex: "-1",
190193
onClick: stopPropagation,

specs/Modal.spec.js

+11
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ describe('Modal', function () {
104104
unmountModal();
105105
});
106106

107+
it('overrides the default styles when a custom classname is used', function () {
108+
var modal = renderModal({isOpen: true, className: 'myClass'});
109+
equal(modal.portal.refs.content.style.top, '');
110+
unmountModal();
111+
});
112+
113+
it('overrides the default styles when a custom overlayClassName is used', function () {
114+
var modal = renderModal({isOpen: true, overlayClassName: 'myOverlayClass'});
115+
equal(modal.portal.refs.overlay.style.backgroundColor, '');
116+
});
117+
107118
it('supports adding style to the modal contents', function () {
108119
var modal = renderModal({isOpen: true, style: {content: {width: '20px'}}});
109120
equal(modal.portal.refs.content.style.width, '20px');

0 commit comments

Comments
 (0)