From 75f0eb81ab421f791b56f140bd0aea2aae23be24 Mon Sep 17 00:00:00 2001 From: luckyCao Date: Wed, 14 Aug 2019 10:52:47 +0800 Subject: [PATCH] Table: fix chrome crash when set thead css display to none (#16956) --- packages/table/src/table-layout.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/table/src/table-layout.js b/packages/table/src/table-layout.js index d11f35263..f8c9121c3 100644 --- a/packages/table/src/table-layout.js +++ b/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;