Skip to content

Commit 63bee72

Browse files
committed
[fixed] Custom classnames override default styles
This makes it so if you provide a custom className it will override all the default styling, relying solely on the style props you pass in and the className itself. Prior to this commit, providing a className or overlayClassName doesn't really have any effect because the style attribute has higher precedent when applying styles.
1 parent 1a0a069 commit 63bee72

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

Diff for: 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,

Diff for: 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)