Filter out undefined/null children which won't render
This commit is contained in:
parent
1dd2cbed63
commit
38d5c7d5c5
1 changed files with 6 additions and 2 deletions
|
@ -42,7 +42,11 @@ module.exports = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
var childsJsx = this.props.children;
|
var childsJsx = this.props.children;
|
||||||
var overflowJsx;
|
var overflowJsx;
|
||||||
var childCount = React.Children.count(this.props.children);
|
var childArray = React.Children.toArray(this.props.children).filter((c) => {
|
||||||
|
return c != null;
|
||||||
|
});
|
||||||
|
|
||||||
|
var childCount = childArray.length;
|
||||||
|
|
||||||
if (this.props.truncateAt >= 0) {
|
if (this.props.truncateAt >= 0) {
|
||||||
var overflowCount = childCount - this.props.truncateAt;
|
var overflowCount = childCount - this.props.truncateAt;
|
||||||
|
@ -51,7 +55,7 @@ module.exports = React.createClass({
|
||||||
overflowJsx = this.props.createOverflowElement(
|
overflowJsx = this.props.createOverflowElement(
|
||||||
overflowCount, childCount
|
overflowCount, childCount
|
||||||
);
|
);
|
||||||
var childArray = React.Children.toArray(this.props.children);
|
|
||||||
// cut out the overflow elements
|
// cut out the overflow elements
|
||||||
childArray.splice(childCount - overflowCount, overflowCount);
|
childArray.splice(childCount - overflowCount, overflowCount);
|
||||||
childsJsx = childArray; // use what is left
|
childsJsx = childArray; // use what is left
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue