improve tabs demo (#14701)

This commit is contained in:
gyh9457 2019-02-04 11:29:28 +08:00 committed by zombieJ
parent 0d65f0578d
commit c895c809f9
2 changed files with 12 additions and 4 deletions

View File

@ -55,8 +55,12 @@ class Demo extends React.Component {
}
});
const panes = this.state.panes.filter(pane => pane.key !== targetKey);
if (lastIndex >= 0 && activeKey === targetKey) {
activeKey = panes[lastIndex].key;
if (panes.length && activeKey === targetKey) {
if (lastIndex >= 0) {
activeKey = panes[lastIndex].key;
} else {
activeKey = panes[0].key;
}
}
this.setState({ panes, activeKey });
}

View File

@ -61,8 +61,12 @@ class Demo extends React.Component {
}
});
const panes = this.state.panes.filter(pane => pane.key !== targetKey);
if (lastIndex >= 0 && activeKey === targetKey) {
activeKey = panes[lastIndex].key;
if (panes.length && activeKey === targetKey) {
if (lastIndex >= 0) {
activeKey = panes[lastIndex].key;
} else {
activeKey = panes[0].key;
}
}
this.setState({ panes, activeKey });
}