mirror of
https://gitee.com/vant-contrib/vant-weapp.git
synced 2025-04-06 03:58:05 +08:00
[bugfix] Tab: line width can be zero (#900)
This commit is contained in:
parent
10a76f2982
commit
be1dfd28e6
@ -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;
|
||||||
`
|
`
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user