From be1dfd28e6d738d0a11587a2a71b8b26955e3bc7 Mon Sep 17 00:00:00 2001 From: neverland Date: Tue, 13 Nov 2018 21:47:39 +0800 Subject: [PATCH] [bugfix] Tab: line width can be zero (#900) --- packages/tabs/index.ts | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/tabs/index.ts b/packages/tabs/index.ts index 3e6a9c15..469f8a1d 100644 --- a/packages/tabs/index.ts +++ b/packages/tabs/index.ts @@ -24,7 +24,10 @@ VantComponent({ props: { color: String, - lineWidth: Number, + lineWidth: { + type: Number, + value: -1 + }, active: { type: Number, value: 0 @@ -118,20 +121,29 @@ VantComponent({ return; } + const { + color, + active, + duration, + lineWidth + } = this.data; + this.getRect('.van-tab', true).then(rects => { - const rect = rects[this.data.active]; - const width = this.data.lineWidth || (rect.width / 2); + const rect = rects[active]; + const width = (lineWidth !== -1) ? lineWidth : rect.width / 2; + let left = rects - .slice(0, this.data.active) + .slice(0, active) .reduce((prev, curr) => prev + curr.width, 0); + left += (rect.width - width) / 2; this.setData({ lineStyle: ` width: ${width}px; - background-color: ${this.data.color}; + background-color: ${color}; transform: translateX(${left}px); - transition-duration: ${this.data.duration}s; + transition-duration: ${duration}s; ` }); });