浏览代码

Table: fix chrome crash when set thead css display to none (#16956)

luckyCao 6 年之前
父节点
当前提交
75f0eb81ab
共有 1 个文件被更改,包括 17 次插入1 次删除
  1. 17 1
      packages/table/src/table-layout.js

+ 17 - 1
packages/table/src/table-layout.js

@@ -95,8 +95,13 @@ class TableLayout {
     this.appendHeight = appendWrapper ? appendWrapper.offsetHeight : 0;
 
     if (this.showHeader && !headerWrapper) return;
+
+    // fix issue (https://github.com/ElemeFE/element/pull/16956)
+    const headerTrElm = headerWrapper.querySelector('.el-table__header tr');
+    const noneHeader = this.headerDisplayNone(headerTrElm);
+
     const headerHeight = this.headerHeight = !this.showHeader ? 0 : headerWrapper.offsetHeight;
-    if (this.showHeader && headerWrapper.offsetWidth > 0 && (this.table.columns || []).length > 0 && headerHeight < 2) {
+    if (this.showHeader && !noneHeader && headerWrapper.offsetWidth > 0 && (this.table.columns || []).length > 0 && headerHeight < 2) {
       return Vue.nextTick(() => this.updateElsHeight());
     }
     const tableHeight = this.tableHeight = this.table.$el.clientHeight;
@@ -113,6 +118,17 @@ class TableLayout {
     this.notifyObservers('scrollable');
   }
 
+  headerDisplayNone(elm) {
+    let headerChild = elm;
+    while (headerChild.tagName !== 'DIV') {
+      if (getComputedStyle(headerChild).display === 'none') {
+        return true;
+      }
+      headerChild = headerChild.parentElement;
+    }
+    return false;
+  }
+
   updateColumnsWidth() {
     if (Vue.prototype.$isServer) return;
     const fit = this.fit;