mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-22 14:39:16 +08:00
fix(Tabs): should keep active value after insert item (#7445)
This commit is contained in:
parent
1c38b7385b
commit
134d8ccd6f
@ -43,3 +43,21 @@ exports[`insert tab with child component 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</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>
|
||||||
|
`;
|
||||||
|
@ -26,6 +26,27 @@ test('insert tab dynamically', async () => {
|
|||||||
expect(wrapper).toMatchSnapshot();
|
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
|
// this case will throw wierd error in index.spec.js
|
||||||
// so separate it
|
// so separate it
|
||||||
test('insert tab with child component', async () => {
|
test('insert tab with child component', async () => {
|
||||||
|
@ -142,7 +142,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
children() {
|
children() {
|
||||||
this.setCurrentIndexByName(this.currentName || this.active);
|
this.setCurrentIndexByName(this.active || this.currentName);
|
||||||
this.setLine();
|
this.setLine();
|
||||||
|
|
||||||
this.$nextTick(() => {
|
this.$nextTick(() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user