Skip to content

Commit

Permalink
Merge pull request baidu#9510 from allenve/master
Browse files Browse the repository at this point in the history
fix: issue: 8308 Tabs active 激活问题
  • Loading branch information
allenve committed Jan 24, 2024
2 parents 55a0618 + f58c032 commit d705a2e
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/amis/src/renderers/Tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
return;
}

// 当前 tab 可能不可见,所以需要自动切到一个可见的 tab, 向前找,找一圈
// 当前 tab 可能不可见,所以需要自动切到一个可见的 tab, 左右左右找, 直到找到一个可见的 tab
const tabIndex = findIndex(localTabs, (tab: TabSource, index) =>
tab.hash ? tab.hash === key : index === key
);
Expand All @@ -539,14 +539,20 @@ export default class Tabs extends React.Component<TabsProps, TabsState> {
localTabs[tabIndex] &&
!isVisible(localTabs[tabIndex], this.props.data)
) {
let len = localTabs.length;
let i = tabIndex - 1 + len;
let tries = len - 1;

while (tries--) {
const index = i-- % len;
if (isVisible(localTabs[index], data)) {
let activeKey = localTabs[index].hash || index;
const len = localTabs.length;
let left = tabIndex;
let right = tabIndex;

while (left-- >= 0 || right++ < len) {
let activeKey = null;

if (left >= 0 && isVisible(localTabs[left], data)) {
activeKey = localTabs[left].hash || left;
} else if (right < len && isVisible(localTabs[right], data)) {
activeKey = localTabs[right].hash || right;
}

if (activeKey !== null) {
this.setState({
activeKey: (this.activeKey = activeKey)
});
Expand Down

0 comments on commit d705a2e

Please sign in to comment.