fix(Tabs): should keep active value after insert item (#7445)

This commit is contained in:
neverland 2020-10-29 21:48:54 +08:00 committed by GitHub
parent 1c38b7385b
commit 134d8ccd6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View File

@ -43,3 +43,21 @@ exports[`insert tab with child component 1`] = `
</div>
</div>
`;
exports[`insert tab with name dynamically 1`] = `
<div class="van-tabs van-tabs--line">
<div class="van-tabs__wrap">
<div role="tablist" class="van-tabs__nav van-tabs__nav--line">
<div role="tab" class="van-tab"><span class="van-tab__text van-tab__text--ellipsis">1</span></div>
<div role="tab" aria-selected="true" class="van-tab van-tab--active"><span class="van-tab__text van-tab__text--ellipsis">2</span></div>
<div class="van-tabs__line" style="transform: translateX(0px) translateX(-50%);"></div>
</div>
</div>
<div class="van-tabs__content">
<div role="tabpanel" class="van-tab__pane" style="display: none;">
<!---->
</div>
<div role="tabpanel" class="van-tab__pane" style="">1</div>
</div>
</div>
`;

View File

@ -26,6 +26,27 @@ test('insert tab dynamically', async () => {
expect(wrapper).toMatchSnapshot();
});
test('insert tab with name dynamically', async () => {
const wrapper = mount({
template: `
<van-tabs v-model="active">
<van-tab v-if="insert" title="1" name="bar">2</van-tab>
<van-tab title="2" name="foo">1</van-tab>
</van-tabs>
`,
data() {
return {
insert: false,
active: [{ name: 'foo', title: 'foo' }],
};
},
});
await later();
wrapper.setData({ insert: true });
expect(wrapper).toMatchSnapshot();
});
// this case will throw wierd error in index.spec.js
// so separate it
test('insert tab with child component', async () => {

View File

@ -142,7 +142,7 @@ export default createComponent({
},
children() {
this.setCurrentIndexByName(this.currentName || this.active);
this.setCurrentIndexByName(this.active || this.currentName);
this.setLine();
this.$nextTick(() => {