[bugfix] Tab: should not swipe to disabled tab (#1704)

This commit is contained in:
neverland 2018-08-27 20:27:48 +08:00 committed by GitHub
parent d05c8ed025
commit fe3eb10bd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -262,7 +262,8 @@ export default create({
}, },
setCurActive(active) { setCurActive(active) {
if (active !== this.curActive) { active = this.findAvailableTab(active, active < this.curActive);
if (this.isDef(active) && active !== this.curActive) {
this.$emit('input', active); this.$emit('input', active);
if (this.curActive !== null) { 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 // emit event when clicked
onClick(index) { onClick(index) {
const { title, disabled } = this.tabs[index]; const { title, disabled } = this.tabs[index];