Skip to content

Commit 4ed6fe0

Browse files
committed
Merge pull request react-bootstrap#379 from taion/jjia/panel-fill-bugfix
Properly render panel-filling single children
2 parents 2cda33a + db0f0bb commit 4ed6fe0

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/Panel.jsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ var Panel = React.createClass({
8383
return {key: bodyElements.length};
8484
}
8585

86+
function addPanelChild (child) {
87+
bodyElements.push(cloneWithProps(child, getProps()));
88+
}
89+
8690
function addPanelBody (children) {
8791
bodyElements.push(
8892
<div className="panel-body" {...getProps()}>
@@ -93,7 +97,11 @@ var Panel = React.createClass({
9397

9498
// Handle edge cases where we should not iterate through children.
9599
if (!Array.isArray(allChildren) || allChildren.length == 0) {
96-
addPanelBody(allChildren);
100+
if (this.shouldRenderFill(allChildren)) {
101+
addPanelChild(allChildren);
102+
} else {
103+
addPanelBody(allChildren);
104+
}
97105
} else {
98106
var panelBodyChildren = [];
99107

@@ -107,22 +115,26 @@ var Panel = React.createClass({
107115
}
108116

109117
allChildren.forEach(function(child) {
110-
if (React.isValidElement(child) && child.props.fill != null) {
118+
if (this.shouldRenderFill(child)) {
111119
maybeRenderPanelBody();
112120

113121
// Separately add the filled element.
114-
bodyElements.push(cloneWithProps(child, getProps()));
122+
addPanelChild(child);
115123
} else {
116124
panelBodyChildren.push(child);
117125
}
118-
});
126+
}.bind(this));
119127

120128
maybeRenderPanelBody();
121129
}
122130

123131
return bodyElements;
124132
},
125133

134+
shouldRenderFill: function (child) {
135+
return React.isValidElement(child) && child.props.fill != null
136+
},
137+
126138
renderHeading: function () {
127139
var header = this.props.header;
128140

test/PanelSpec.jsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ describe('Panel', function () {
149149
);
150150

151151
var children = instance.getDOMNode().children;
152+
assert.equal(children.length, 3);
152153

153154
assert.equal(children[0].nodeName, 'DIV');
154155
assert.ok(children[0].className.match(/\bpanel-body\b/));
@@ -158,5 +159,19 @@ describe('Panel', function () {
158159

159160
assert.equal(children[2].nodeName, 'DIV');
160161
assert.ok(children[2].className.match(/\bpanel-body\b/));
161-
})
162+
});
163+
164+
it('Should not wrap single panel-fill table in a panel body', function () {
165+
var instance = ReactTestUtils.renderIntoDocument(
166+
<Panel>
167+
<Table fill />
168+
</Panel>
169+
);
170+
171+
var children = instance.getDOMNode().children;
172+
assert.equal(children.length, 1);
173+
174+
assert.equal(children[0].nodeName, 'TABLE');
175+
assert.notOk(children[0].className.match(/\bpanel-body\b/));
176+
});
162177
});

0 commit comments

Comments
 (0)