From 7a888af0620a9671c362777c9bb0fcf8660ea052 Mon Sep 17 00:00:00 2001 From: Song Date: Tue, 26 Mar 2019 17:17:20 +0800 Subject: [PATCH] fix bug: if new children's length is less than the old ones, no tab will be selected. This fix will select the 0 index tab when new children's length is less then the old ones. --- index.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index af94d866..910b816b 100644 --- a/index.js +++ b/index.js @@ -108,11 +108,15 @@ const ScrollableTabView = createReactClass({ }, componentWillReceiveProps(props) { + let currentPage = this.state.currentPage; if (props.children !== this.props.children) { - this.updateSceneKeys({ page: this.state.currentPage, children: props.children, }); + if (currentPage >= props.children.length) { + currentPage = 0; + } + this.updateSceneKeys({ page: currentPage, children: props.children, }); } - if (props.page >= 0 && props.page !== this.state.currentPage) { + if (props.page >= 0 && props.page !== currentPage) { this.goToPage(props.page); } },