diff --git a/src/renderers/Tabs.tsx b/src/renderers/Tabs.tsx index d986a565..fd5099a5 100644 --- a/src/renderers/Tabs.tsx +++ b/src/renderers/Tabs.tsx @@ -106,6 +106,35 @@ export default class Tabs extends React.Component { } } + componentDidUpdate() { + const { + tabs, + data + } = this.props; + + if (!Array.isArray(tabs)) { + return; + } + + const tabIndex = findIndex(tabs, (tab: TabProps, index) => + tab.hash ? tab.hash === this.state.activeKey : index === this.state.activeKey + ); + + if (tabs[tabIndex] && !isVisible(tabs[tabIndex], this.props.data)) { + let i = tabIndex - 1; + while (tabs[i]) { + if (isVisible(tabs[i], data)) { + let activeKey = tabs[i].hash || i; + this.setState({ + activeKey + }) + break; + } + i--; + } + } + } + handleSelect(key: any) { const {env} = this.props; @@ -162,7 +191,6 @@ export default class Tabs extends React.Component { } const mode = tabsMode || dMode; - const visibleTabs = tabs.filter(tab => isVisible(tab, data)); return ( { >
{ mountOnEnter={mountOnEnter} unmountOnExit={unmountOnExit} > - {visibleTabs.map((tab, index) => ( + {tabs.map((tab, index) => isVisible(tab, data) ? ( { ? tabRender(tab, this.props) : render(`tab/${index}`, tab.tab || tab.body || '')} - ))} + ) : null)}