From 134d8ccd6f3a0a24c9b1087de540a789e639f291 Mon Sep 17 00:00:00 2001 From: neverland Date: Thu, 29 Oct 2020 21:48:54 +0800 Subject: [PATCH] fix(Tabs): should keep active value after insert item (#7445) --- .../test/__snapshots__/insert.spec.js.snap | 18 ++++++++++++++++ src/tab/test/insert.spec.js | 21 +++++++++++++++++++ src/tabs/index.js | 2 +- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/tab/test/__snapshots__/insert.spec.js.snap b/src/tab/test/__snapshots__/insert.spec.js.snap index 15b4c1272..bd82b97fe 100644 --- a/src/tab/test/__snapshots__/insert.spec.js.snap +++ b/src/tab/test/__snapshots__/insert.spec.js.snap @@ -43,3 +43,21 @@ exports[`insert tab with child component 1`] = ` `; + +exports[`insert tab with name dynamically 1`] = ` +
+
+
+ + +
+
+
+
+ +
1
+
+
+`; diff --git a/src/tab/test/insert.spec.js b/src/tab/test/insert.spec.js index bfd4a3edb..3c28b4053 100644 --- a/src/tab/test/insert.spec.js +++ b/src/tab/test/insert.spec.js @@ -26,6 +26,27 @@ test('insert tab dynamically', async () => { expect(wrapper).toMatchSnapshot(); }); +test('insert tab with name dynamically', async () => { + const wrapper = mount({ + template: ` + + 2 + 1 + + `, + 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 () => { diff --git a/src/tabs/index.js b/src/tabs/index.js index 44126579d..496790e62 100644 --- a/src/tabs/index.js +++ b/src/tabs/index.js @@ -142,7 +142,7 @@ export default createComponent({ }, children() { - this.setCurrentIndexByName(this.currentName || this.active); + this.setCurrentIndexByName(this.active || this.currentName); this.setLine(); this.$nextTick(() => {