Skip to content

Commit 592a346

Browse files
author
Jimmy Jia
committed
[fixed] Forward classes to panel title
1 parent f8a7243 commit 592a346

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

src/Panel.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,19 @@ const Panel = React.createClass({
156156
if (!React.isValidElement(header) || Array.isArray(header)) {
157157
header = collapsible ?
158158
this.renderCollapsableTitle(header) : header;
159-
} else if (collapsible) {
160-
161-
header = cloneElement(header, {
162-
className: classNames(this.prefixClass('title')),
163-
children: this.renderAnchor(header.props.children)
164-
});
165159
} else {
160+
const className = classNames(
161+
this.prefixClass('title'), header.props.className
162+
);
166163

167-
header = cloneElement(header, {
168-
className: classNames(this.prefixClass('title'))
169-
});
164+
if (collapsible) {
165+
header = cloneElement(header, {
166+
className,
167+
children: this.renderAnchor(header.props.children)
168+
});
169+
} else {
170+
header = cloneElement(header, {className});
171+
}
170172
}
171173

172174
return (

test/PanelSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,18 @@ describe('Panel', function () {
5858
assert.equal(header.firstChild.firstChild.innerHTML, 'Heading');
5959
});
6060

61+
it('Should have custom component header with custom class', function () {
62+
let header = <h3 className="custom-class">Heading</h3>,
63+
instance = ReactTestUtils.renderIntoDocument(
64+
<Panel header={header}>Panel content</Panel>
65+
);
66+
header = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'panel-heading').getDOMNode();
67+
assert.equal(header.firstChild.nodeName, 'H3');
68+
assert.ok(header.firstChild.className.match(/\bpanel-title\b/));
69+
assert.ok(header.firstChild.className.match(/\bcustom-class\b/));
70+
assert.equal(header.firstChild.innerHTML, 'Heading');
71+
});
72+
6173
it('Should have footer', function () {
6274
let instance = ReactTestUtils.renderIntoDocument(
6375
<Panel footer="Footer">Panel content</Panel>

0 commit comments

Comments
 (0)