Skip to content

Commit

Permalink
fix(TabSwitcher): check for child displayName (#518)
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Roux authored and sun-tea committed May 6, 2019
1 parent 5e8a8ef commit ff36178
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/TabSwitcher/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@ const TabSwitcher = ({ children, defaultIndex, index, isCompacted, onChange }) =
const [activeIndex, setActiveIndex] = useState(defaultIndex);

const content = Children.map(children, child => {
// ignore random <div/>s etc.
if (child) {
if (typeof child.type === 'string') return child;
if (child.type.displayName === 'Panes') {
return cloneElement(child, {
activeIndex: isControlled ? index : activeIndex,
isCompacted,
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 ff36178

Please sign in to comment.