Skip to content

Commit

Permalink
fix(TabSwitcher): check that child is not null (#519)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-tea authored and Thomas Roux committed May 6, 2019
1 parent 55cab58 commit 0f07300
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/TabSwitcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,26 @@ const TabSwitcher = ({ children, defaultIndex, index, isCompacted, onChange }) =
const [activeIndex, setActiveIndex] = useState(defaultIndex);

const content = Children.map(children, child => {
if (child.type.displayName === 'Panes') {
return cloneElement(child, {
activeIndex: isControlled ? index : activeIndex,
isCompacted: isCompacted,
});
} else if (child.type.displayName === 'Tabs') {
return cloneElement(child, {
activeIndex: isControlled ? index : activeIndex,
isCompacted: isCompacted,
onActiveTab: index => {
onChange && onChange(index);
if (!isControlled) {
setActiveIndex(index);
}
},
});
} else {
return child;
if (child) {
if (child.type.displayName === 'Panes') {
return cloneElement(child, {
activeIndex: isControlled ? index : activeIndex,
isCompacted: isCompacted,
});
} else if (child.type.displayName === 'Tabs') {
return cloneElement(child, {
activeIndex: isControlled ? index : activeIndex,
isCompacted: isCompacted,
onActiveTab: index => {
onChange && onChange(index);
if (!isControlled) {
setActiveIndex(index);
}
},
});
} else {
return child;
}
}
});

Expand Down

0 comments on commit 0f07300

Please sign in to comment.