Skip to content
This repository has been archived by the owner on Oct 19, 2021. It is now read-only.

Commit

Permalink
fix(Tabs): avoid stale tab ref cache (#2224)
Browse files Browse the repository at this point in the history
The problem happens when `selected` and `children` changes at the same
time.

Fixes #2204.
  • Loading branch information
asudoh authored Apr 20, 2019
1 parent 4bb5cb9 commit 2335c44
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/components/Tabs/Tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ export default class Tabs extends React.Component {
return React.Children.map(this.props.children, tab => tab);
}

getTabAt = index => {
getTabAt = (index, useFresh) => {
return (
this[`tab${index}`] || React.Children.toArray(this.props.children)[index]
(!useFresh && this[`tab${index}`]) ||
React.Children.toArray(this.props.children)[index]
);
};

Expand Down Expand Up @@ -251,7 +252,7 @@ export default class Tabs extends React.Component {
}),
};

const selectedTab = this.getTabAt(this.state.selected);
const selectedTab = this.getTabAt(this.state.selected, true);
const selectedLabel = selectedTab ? selectedTab.props.label : '';

return (
Expand Down

0 comments on commit 2335c44

Please sign in to comment.