Skip to content

Commit

Permalink
fix(TabSwitcher): add guard for null children (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
sun-tea authored and Thomas Roux committed Apr 9, 2019
1 parent 786acef commit a6577ee
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/TabSwitcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ const TabSwitcher = ({ children, defaultIndex, index, isCompacted, onChange }) =

const content = Children.map(children, child => {
// ignore random <div/>s etc.
if (typeof child.type === 'string') return child;
return cloneElement(child, {
activeIndex: isControlled ? index : activeIndex,
isCompacted,
onActiveTab: index => {
onChange && onChange(index);
if (!isControlled) {
setActiveIndex(index);
}
},
});
if (child) {
if (typeof child.type === 'string') return child;
return cloneElement(child, {
activeIndex: isControlled ? index : activeIndex,
isCompacted,
onActiveTab: index => {
onChange && onChange(index);
if (!isControlled) {
setActiveIndex(index);
}
},
});
}
});

return <div>{content}</div>;
Expand Down

0 comments on commit a6577ee

Please sign in to comment.