From fe3eb10bd3fc7ee98413774e46baefcd25da3ffd Mon Sep 17 00:00:00 2001 From: neverland Date: Mon, 27 Aug 2018 20:27:48 +0800 Subject: [PATCH] [bugfix] Tab: should not swipe to disabled tab (#1704) --- packages/tabs/index.vue | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/tabs/index.vue b/packages/tabs/index.vue index 8a158d329..4259c9b05 100644 --- a/packages/tabs/index.vue +++ b/packages/tabs/index.vue @@ -262,7 +262,8 @@ export default create({ }, setCurActive(active) { - if (active !== this.curActive) { + active = this.findAvailableTab(active, active < this.curActive); + if (this.isDef(active) && active !== this.curActive) { this.$emit('input', active); if (this.curActive !== null) { @@ -272,6 +273,16 @@ export default create({ } }, + findAvailableTab(index, reverse) { + const diff = reverse ? -1 : 1; + while (index >= 0 && index < this.tabs.length) { + if (!this.tabs[index].disabled) { + return index; + } + index += diff; + } + }, + // emit event when clicked onClick(index) { const { title, disabled } = this.tabs[index];