[bugfix] Tab: should not have line animation when inited (#2459)

This commit is contained in:
neverland 2019-01-07 19:22:40 +08:00 committed by GitHub
parent 2c3458587e
commit dd20a170ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 11 deletions

View File

@ -28,20 +28,20 @@ exports[`change tabs data 2`] = `
<div class="van-tabs van-tabs--line"> <div class="van-tabs van-tabs--line">
<div class="van-tabs__wrap van-hairline--top-bottom"> <div class="van-tabs__wrap van-hairline--top-bottom">
<div class="van-tabs__nav van-tabs__nav--line" style="border-color: #f44;"> <div class="van-tabs__nav van-tabs__nav--line" style="border-color: #f44;">
<div class="van-tabs__line" style="background-color: rgb(255, 68, 68);"></div> <div class="van-tabs__line" style="background-color: rgb(255, 68, 68); width: 2px; transform: translateX(-1px);"></div>
<div class="van-tab van-tab--active"><span class="van-ellipsis">title1</span></div> <div class="van-tab van-tab--active"><span class="van-ellipsis">title1</span></div>
<div class="van-tab"><span class="van-ellipsis"></span></div> <div class="van-tab">
<div><span>title2</span></div>
</div>
<div class="van-tab van-tab--disabled"><span class="van-ellipsis">title3</span></div> <div class="van-tab van-tab--disabled"><span class="van-ellipsis">title3</span></div>
</div> </div>
</div> </div>
<div class="van-tabs__content"> <div class="van-tabs__content">
<div class="van-tab__pane" style=""> <div class="van-tab__pane" style="">Text
<!---->
<!----> <!---->
</div> </div>
<div class="van-tab__pane" style="display: none;"> <div class="van-tab__pane" style="display: none;">
<!----> <!---->
<div><span>title2</span></div>
</div> </div>
<div class="van-tab__pane" style="display: none;"> <div class="van-tab__pane" style="display: none;">
<!----> <!---->

View File

@ -93,5 +93,7 @@ test('change tabs data', async () => {
color: 'blue', color: 'blue',
title1: 'new title1' title1: 'new title1'
}); });
await later();
expect(wrapper).toMatchSnapshot(); expect(wrapper).toMatchSnapshot();
}); });

View File

@ -198,12 +198,9 @@ export default create({
}, },
mounted() { mounted() {
this.correctActive(this.active);
this.setLine();
this.$nextTick(() => { this.$nextTick(() => {
this.inited = true;
this.handlers(true); this.handlers(true);
this.scrollIntoView(true);
}); });
}, },
@ -293,6 +290,8 @@ export default create({
// update nav bar style // update nav bar style
setLine() { setLine() {
const shouldAnimate = this.inited;
this.$nextTick(() => { this.$nextTick(() => {
const { tabs } = this.$refs; const { tabs } = this.$refs;
@ -308,10 +307,13 @@ export default create({
const lineStyle = { const lineStyle = {
width: `${width}px`, width: `${width}px`,
backgroundColor: this.color, backgroundColor: this.color,
transform: `translateX(${left}px)`, transform: `translateX(${left}px)`
transitionDuration: `${this.duration}s`
}; };
if (shouldAnimate) {
lineStyle.transitionDuration = `${this.duration}s`;
}
if (this.isDef(lineHeight)) { if (this.isDef(lineHeight)) {
const height = `${lineHeight}px`; const height = `${lineHeight}px`;
lineStyle.height = height; lineStyle.height = height;