Fixed sync width directive
This commit is contained in:
parent
d5485882e4
commit
64f2d861f2
@ -3,6 +3,7 @@
|
||||
:host {
|
||||
display: flex;
|
||||
height: 30px;
|
||||
flex: 1;
|
||||
|
||||
> div {
|
||||
align-items: center;
|
||||
|
||||
@ -15,6 +15,22 @@ export class SyncWidthDirective implements AfterViewChecked {
|
||||
this.matchWidth();
|
||||
}
|
||||
|
||||
private get _sampleRow(): { tableRow: Element; length: number } {
|
||||
const tableRows = document.getElementsByClassName(this.redactionSyncWidth);
|
||||
let length = 0;
|
||||
let tableRow: Element;
|
||||
|
||||
for (let idx = 0; idx < tableRows.length; ++idx) {
|
||||
const row = tableRows.item(idx);
|
||||
if (row.children.length > length) {
|
||||
length = row.children.length;
|
||||
tableRow = row;
|
||||
}
|
||||
}
|
||||
|
||||
return { tableRow, length };
|
||||
}
|
||||
|
||||
@debounce(0)
|
||||
matchWidth() {
|
||||
const headerItems = this.el.nativeElement.children;
|
||||
@ -22,13 +38,18 @@ export class SyncWidthDirective implements AfterViewChecked {
|
||||
|
||||
if (!tableRows || !tableRows.length) return;
|
||||
|
||||
const tableRow = tableRows[0];
|
||||
if (tableRow.children.length !== headerItems.length) return;
|
||||
const { tableRow, length } = this._sampleRow;
|
||||
|
||||
for (let idx = 0; idx < headerItems.length - 1; ++idx) {
|
||||
const hasExtraColumns = headerItems.length !== length ? 1 : 0;
|
||||
|
||||
for (let idx = 0; idx < length - hasExtraColumns - 1; ++idx) {
|
||||
headerItems[idx].style.width = `${tableRow.children[idx].getBoundingClientRect().width}px`;
|
||||
headerItems[idx].style.minWidth = `${tableRow.children[idx].getBoundingClientRect().width}px`;
|
||||
}
|
||||
|
||||
for (let idx = length - hasExtraColumns - 1; idx < headerItems.length; ++idx) {
|
||||
headerItems[idx].style.minWidth = `0`;
|
||||
}
|
||||
}
|
||||
|
||||
@HostListener('window:resize')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user