[bugfix] Tab: line width can be zero (#900)

This commit is contained in:
neverland 2018-11-13 21:47:39 +08:00 committed by GitHub
parent 10a76f2982
commit be1dfd28e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,10 @@ VantComponent({
props: { props: {
color: String, color: String,
lineWidth: Number, lineWidth: {
type: Number,
value: -1
},
active: { active: {
type: Number, type: Number,
value: 0 value: 0
@ -118,20 +121,29 @@ VantComponent({
return; return;
} }
const {
color,
active,
duration,
lineWidth
} = this.data;
this.getRect('.van-tab', true).then(rects => { this.getRect('.van-tab', true).then(rects => {
const rect = rects[this.data.active]; const rect = rects[active];
const width = this.data.lineWidth || (rect.width / 2); const width = (lineWidth !== -1) ? lineWidth : rect.width / 2;
let left = rects let left = rects
.slice(0, this.data.active) .slice(0, active)
.reduce((prev, curr) => prev + curr.width, 0); .reduce((prev, curr) => prev + curr.width, 0);
left += (rect.width - width) / 2; left += (rect.width - width) / 2;
this.setData({ this.setData({
lineStyle: ` lineStyle: `
width: ${width}px; width: ${width}px;
background-color: ${this.data.color}; background-color: ${color};
transform: translateX(${left}px); transform: translateX(${left}px);
transition-duration: ${this.data.duration}s; transition-duration: ${duration}s;
` `
}); });
}); });