Skip to content

Commit

Permalink
Recompute column width on window resize
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowbas authored and bas080 committed Jan 10, 2025
1 parent 3438fcd commit ef2bdea
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/app/resizable-button/resizable-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,23 @@ export class ResizableButtonComponent implements AfterViewInit {

ngAfterViewInit() {
const parentElement = this.elementRef.nativeElement.parentElement;
this.initialWidth = window.getComputedStyle(parentElement).width;

if (parentElement) {
this.widthChange.emit(parentElement.offsetWidth);
}
this.initialWidth = parentElement.style.width;

this.resetWidth()
}

resetWidth() {
const parentElement = this.elementRef.nativeElement.parentElement;

parentElement.style.width = this.initialWidth;

setTimeout(() => {
const width = window.getComputedStyle(parentElement).width;

parentElement.style.width = width;
this.widthChange.emit(parentElement.offsetWidth);
}, 10);
}

@HostListener('window:resize')
Expand Down

0 comments on commit ef2bdea

Please sign in to comment.