Skip to content

Commit 7c1defd

Browse files
fix: update condition to prevent undefined error in CI
1 parent e6dfd0b commit 7c1defd

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

packages/primeng/src/scroller/scroller.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -924,10 +924,18 @@ export class Scroller extends BaseComponent<VirtualScrollerPassThrough> {
924924

925925
setSize() {
926926
if (this.elementViewChild?.nativeElement) {
927-
const parentElement = this.elementViewChild.nativeElement.parentElement.parentElement;
928-
const width = this._scrollWidth || `${this.elementViewChild.nativeElement.offsetWidth || parentElement.offsetWidth}px`;
929-
const height = this._scrollHeight || `${this.elementViewChild.nativeElement.offsetHeight || parentElement.offsetHeight}px`;
930-
const setProp = (_name: string, _value: any) => ((<ElementRef>this.elementViewChild).nativeElement.style[_name] = _value);
927+
const nativeElement = this.elementViewChild.nativeElement;
928+
const parentElement = nativeElement.parentElement?.parentElement;
929+
930+
const elementWidth = nativeElement.offsetWidth;
931+
const parentWidth = parentElement?.offsetWidth || 0;
932+
const width = this._scrollWidth || `${elementWidth || parentWidth}px`;
933+
934+
const elementHeight = nativeElement.offsetHeight;
935+
const parentHeight = parentElement?.offsetHeight || 0;
936+
const height = this._scrollHeight || `${elementHeight || parentHeight}px`;
937+
938+
const setProp = (_name: string, _value: any) => (nativeElement.style[_name] = _value);
931939

932940
if (this.both || this.horizontal) {
933941
setProp('height', height);

0 commit comments

Comments
 (0)