mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-03 04:18:29 +08:00
前面可能找不着,所以接着往后找
This commit is contained in:
parent
0a7078bf93
commit
9a6e5dbea6
@ -116,21 +116,25 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 当前 tab 可能不可见,所以需要自动切到一个可见的 tab, 向前找,找一圈
|
||||||
const tabIndex = findIndex(tabs, (tab: TabProps, index) =>
|
const tabIndex = findIndex(tabs, (tab: TabProps, index) =>
|
||||||
tab.hash ? tab.hash === this.state.activeKey : index === this.state.activeKey
|
tab.hash ? tab.hash === this.state.activeKey : index === this.state.activeKey
|
||||||
);
|
);
|
||||||
|
|
||||||
if (tabs[tabIndex] && !isVisible(tabs[tabIndex], this.props.data)) {
|
if (tabs[tabIndex] && !isVisible(tabs[tabIndex], this.props.data)) {
|
||||||
let i = tabIndex - 1;
|
let len = tabs.length;
|
||||||
while (tabs[i]) {
|
let i = (tabIndex - 1) + len;
|
||||||
if (isVisible(tabs[i], data)) {
|
let tries = len - 1;
|
||||||
let activeKey = tabs[i].hash || i;
|
|
||||||
|
while (tries--) {
|
||||||
|
const index = (i--) % len;
|
||||||
|
if (isVisible(tabs[index], data)) {
|
||||||
|
let activeKey = tabs[index].hash || index;
|
||||||
this.setState({
|
this.setState({
|
||||||
activeKey
|
activeKey
|
||||||
})
|
})
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i--;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user