Skip to content

Commit

Permalink
fix(scroller): contentEl might be undefined if calling setTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
jase88 committed Oct 1, 2024
1 parent d6c7ffc commit ab3f8d4
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/app/components/dom/domhandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ export class DomHandler {
return height;
}

public static getHeight(el): number {
public static getHeight(el: HTMLElement): number {
let height = el.offsetHeight;
let style = getComputedStyle(el);

Expand All @@ -407,7 +407,7 @@ export class DomHandler {
return height;
}

public static getWidth(el): number {
public static getWidth(el: HTMLElement): number {
let width = el.offsetWidth;
let style = getComputedStyle(el);

Expand Down
10 changes: 6 additions & 4 deletions src/app/components/scroller/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ export class Scroller implements OnInit, AfterContentInit, AfterViewChecked, OnD

d_numToleratedItems: any;

contentEl: any;
contentEl: HTMLElement | null | undefined;

contentTemplate: Nullable<TemplateRef<any>>;

Expand Down Expand Up @@ -461,7 +461,7 @@ export class Scroller implements OnInit, AfterContentInit, AfterViewChecked, OnD

initialized: boolean = false;

resizeObserver: any;
resizeObserver: ResizeObserver | null | undefined;

defaultWidth: number | undefined;

Expand Down Expand Up @@ -1061,8 +1061,10 @@ export class Scroller implements OnInit, AfterContentInit, AfterViewChecked, OnD
this.d_numToleratedItems = this._numToleratedItems;
this.defaultWidth = width;
this.defaultHeight = height;
this.defaultContentWidth = DomHandler.getWidth(this.contentEl);
this.defaultContentHeight = DomHandler.getHeight(this.contentEl);
if (this.contentEl) {
this.defaultContentWidth = DomHandler.getWidth(this.contentEl);
this.defaultContentHeight = DomHandler.getHeight(this.contentEl);
}

this.init();
this.calculateAutoSize();
Expand Down

0 comments on commit ab3f8d4

Please sign in to comment.