Commit 9736448b authored by Akshay Jat's avatar Akshay Jat Committed by hetech

Tabs: rerender when label changes (#14496)

* tab: fix active bar bug (#14416)

fix: Tab active bar doesn't resize when tab label changes dynamically

* tab: fix active bar bug

changes done as suggested in review
parent 362953ef
...@@ -51,7 +51,7 @@ ...@@ -51,7 +51,7 @@
watch: { watch: {
label() { label() {
this.$parent.$forceUpdate(); this.$parent.$emit('tabLabelChanged');
} }
} }
}; };
......
...@@ -55,13 +55,14 @@ ...@@ -55,13 +55,14 @@
}, },
methods: { methods: {
calcPaneInstances() { calcPaneInstances(isLabelUpdated = false) {
if (this.$slots.default) { if (this.$slots.default) {
const paneSlots = this.$slots.default.filter(vnode => vnode.tag && const paneSlots = this.$slots.default.filter(vnode => vnode.tag &&
vnode.componentOptions && vnode.componentOptions.Ctor.options.name === 'ElTabPane'); vnode.componentOptions && vnode.componentOptions.Ctor.options.name === 'ElTabPane');
// update indeed // update indeed
const panes = paneSlots.map(({ componentInstance }) => componentInstance); const panes = paneSlots.map(({ componentInstance }) => componentInstance);
if (!(panes.length === this.panes.length && panes.every((pane, index) => pane === this.panes[index]))) { const panesChanged = !(panes.length === this.panes.length && panes.every((pane, index) => pane === this.panes[index]));
if (isLabelUpdated || panesChanged) {
this.panes = panes; this.panes = panes;
} }
} else if (this.panes.length !== 0) { } else if (this.panes.length !== 0) {
...@@ -172,6 +173,8 @@ ...@@ -172,6 +173,8 @@
if (!this.currentName) { if (!this.currentName) {
this.setCurrentName('0'); this.setCurrentName('0');
} }
this.$on('tabLabelChanged', this.calcPaneInstances.bind(null, true));
}, },
mounted() { mounted() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment