Skip to content

Commit 75f0eb8

Browse files
luckyCaoziyoung
authored andcommitted
Table: fix chrome crash when set thead css display to none (#16956)
1 parent a907d39 commit 75f0eb8

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

packages/table/src/table-layout.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ class TableLayout {
9595
this.appendHeight = appendWrapper ? appendWrapper.offsetHeight : 0;
9696

9797
if (this.showHeader && !headerWrapper) return;
98+
99+
// fix issue (https://github.com/ElemeFE/element/pull/16956)
100+
const headerTrElm = headerWrapper.querySelector('.el-table__header tr');
101+
const noneHeader = this.headerDisplayNone(headerTrElm);
102+
98103
const headerHeight = this.headerHeight = !this.showHeader ? 0 : headerWrapper.offsetHeight;
99-
if (this.showHeader && headerWrapper.offsetWidth > 0 && (this.table.columns || []).length > 0 && headerHeight < 2) {
104+
if (this.showHeader && !noneHeader && headerWrapper.offsetWidth > 0 && (this.table.columns || []).length > 0 && headerHeight < 2) {
100105
return Vue.nextTick(() => this.updateElsHeight());
101106
}
102107
const tableHeight = this.tableHeight = this.table.$el.clientHeight;
@@ -113,6 +118,17 @@ class TableLayout {
113118
this.notifyObservers('scrollable');
114119
}
115120

121+
headerDisplayNone(elm) {
122+
let headerChild = elm;
123+
while (headerChild.tagName !== 'DIV') {
124+
if (getComputedStyle(headerChild).display === 'none') {
125+
return true;
126+
}
127+
headerChild = headerChild.parentElement;
128+
}
129+
return false;
130+
}
131+
116132
updateColumnsWidth() {
117133
if (Vue.prototype.$isServer) return;
118134
const fit = this.fit;

0 commit comments

Comments
 (0)