Skip to content

Commit

Permalink
[fixed] Forward classes to panel title
Browse files Browse the repository at this point in the history
  • Loading branch information
Jimmy Jia committed May 15, 2015
1 parent f8a7243 commit 592a346
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,17 +156,19 @@ const Panel = React.createClass({
if (!React.isValidElement(header) || Array.isArray(header)) {
header = collapsible ?
this.renderCollapsableTitle(header) : header;
} else if (collapsible) {

header = cloneElement(header, {
className: classNames(this.prefixClass('title')),
children: this.renderAnchor(header.props.children)
});
} else {
const className = classNames(
this.prefixClass('title'), header.props.className
);

header = cloneElement(header, {
className: classNames(this.prefixClass('title'))
});
if (collapsible) {
header = cloneElement(header, {
className,
children: this.renderAnchor(header.props.children)
});
} else {
header = cloneElement(header, {className});
}
}

return (
Expand Down
12 changes: 12 additions & 0 deletions test/PanelSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,18 @@ describe('Panel', function () {
assert.equal(header.firstChild.firstChild.innerHTML, 'Heading');
});

it('Should have custom component header with custom class', function () {
let header = <h3 className="custom-class">Heading</h3>,
instance = ReactTestUtils.renderIntoDocument(
<Panel header={header}>Panel content</Panel>
);
header = ReactTestUtils.findRenderedDOMComponentWithClass(instance, 'panel-heading').getDOMNode();
assert.equal(header.firstChild.nodeName, 'H3');
assert.ok(header.firstChild.className.match(/\bpanel-title\b/));
assert.ok(header.firstChild.className.match(/\bcustom-class\b/));
assert.equal(header.firstChild.innerHTML, 'Heading');
});

it('Should have footer', function () {
let instance = ReactTestUtils.renderIntoDocument(
<Panel footer="Footer">Panel content</Panel>
Expand Down

0 comments on commit 592a346

Please sign in to comment.