From 592a346c33dfabeb7cffc3562e12db1c57e29d54 Mon Sep 17 00:00:00 2001 From: Jimmy Jia Date: Fri, 15 May 2015 02:25:07 -0400 Subject: [PATCH] [fixed] Forward classes to panel title --- src/Panel.js | 20 +++++++++++--------- test/PanelSpec.js | 12 ++++++++++++ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/Panel.js b/src/Panel.js index 067207d670..4f2ea19a1c 100644 --- a/src/Panel.js +++ b/src/Panel.js @@ -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 ( diff --git a/test/PanelSpec.js b/test/PanelSpec.js index 0817679fc6..7f5416c046 100644 --- a/test/PanelSpec.js +++ b/test/PanelSpec.js @@ -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 =

Heading

, + instance = ReactTestUtils.renderIntoDocument( + Panel content + ); + 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 content