Commit 1a1f7c325c0eee00236b50cd7d48ecf06467e911

Authored by 梁灏
2 parents 75fa706e 915e06db

Merge branch '2.0' of https://github.com/iview/iview into 2.0

Showing 1 changed file with 24 additions and 1 deletions   Show diff stats
src/components/tabs/tabs.vue
@@ -26,7 +26,7 @@ @@ -26,7 +26,7 @@
26 <script> 26 <script>
27 import Icon from '../icon/icon.vue'; 27 import Icon from '../icon/icon.vue';
28 import Render from '../base/render'; 28 import Render from '../base/render';
29 - import { oneOf } from '../../utils/assist'; 29 + import { oneOf, MutationObserver } from '../../utils/assist';
30 import Emitter from '../../mixins/emitter'; 30 import Emitter from '../../mixins/emitter';
31 import elementResizeDetectorMaker from 'element-resize-detector'; 31 import elementResizeDetectorMaker from 'element-resize-detector';
32 32
@@ -310,6 +310,16 @@ @@ -310,6 +310,16 @@
310 }, 310 },
311 handleResize(){ 311 handleResize(){
312 this.updateNavScroll(); 312 this.updateNavScroll();
  313 + },
  314 + isInsideHiddenElement () {
  315 + let parentNode = this.$el.parentNode;
  316 + while(parentNode) {
  317 + if (parentNode.style.display === 'none') {
  318 + return parentNode;
  319 + }
  320 + parentNode = parentNode.parentNode;
  321 + }
  322 + return false;
313 } 323 }
314 }, 324 },
315 watch: { 325 watch: {
@@ -329,9 +339,22 @@ @@ -329,9 +339,22 @@
329 this.showSlot = this.$slots.extra !== undefined; 339 this.showSlot = this.$slots.extra !== undefined;
330 this.observer = elementResizeDetectorMaker(); 340 this.observer = elementResizeDetectorMaker();
331 this.observer.listenTo(this.$refs.navWrap, this.handleResize); 341 this.observer.listenTo(this.$refs.navWrap, this.handleResize);
  342 +
  343 + const hiddenParentNode = this.isInsideHiddenElement();
  344 + if (hiddenParentNode) {
  345 + this.mutationObserver = new MutationObserver(() => {
  346 + if (hiddenParentNode.style.display !== 'none') {
  347 + this.updateBar();
  348 + this.mutationObserver.disconnect();
  349 + }
  350 + });
  351 +
  352 + this.mutationObserver.observe(hiddenParentNode, { attributes: true, childList: true, characterData: true, attributeFilter: ['style'] });
  353 + }
332 }, 354 },
333 beforeDestroy() { 355 beforeDestroy() {
334 this.observer.removeListener(this.$refs.navWrap, this.handleResize); 356 this.observer.removeListener(this.$refs.navWrap, this.handleResize);
  357 + this.mutationObserver.disconnect();
335 } 358 }
336 }; 359 };
337 </script> 360 </script>