Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions packages/fiori/src/DynamicPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ class DynamicPage extends UI5Element {
}

snapTitleByScroll() {
if (!this.dynamicPageTitle || !this.dynamicPageHeader || this.headerPinned) {
if (!this.dynamicPageTitle || !this.dynamicPageHeader || this.headerPinned || !this.scrollContainer) {
return;
}

Expand All @@ -324,7 +324,7 @@ class DynamicPage extends UI5Element {
return;
}

const scrollTop = this.scrollContainer!.scrollTop;
const scrollTop = this.scrollContainer.scrollTop;
const headerHeight = this.dynamicPageHeader.getBoundingClientRect().height;
const lastHeaderSnapped = this._headerSnapped;

Expand All @@ -344,8 +344,8 @@ class DynamicPage extends UI5Element {
// If the header is snapped and the scroll is at the top, scroll down a bit
// to avoid ending in an endless loop of snapping and unsnapping
requestAnimationFrame(() => {
if (this.scrollContainer!.scrollTop === 0) {
this.scrollContainer!.scrollTop = SCROLL_THRESHOLD;
if (this.scrollContainer && this.scrollContainer.scrollTop === 0) {
this.scrollContainer.scrollTop = SCROLL_THRESHOLD;
}
});
} else if (shouldExpand) {
Expand Down Expand Up @@ -376,7 +376,7 @@ class DynamicPage extends UI5Element {
this.headerPinned = !this.headerPinned;
if (this.headerPinned) {
this.showHeaderInStickArea = true;
} else if (this.scrollContainer!.scrollTop === 0) {
} else if (this.scrollContainer && this.scrollContainer.scrollTop === 0) {
this.showHeaderInStickArea = false;
}
this.fireDecoratorEvent("pin-button-toggle");
Expand All @@ -396,8 +396,12 @@ class DynamicPage extends UI5Element {
}

async _toggleHeader() {
if (!this.scrollContainer) {
return;
}

const headerHeight = this.dynamicPageHeader?.getBoundingClientRect().height || 0;
const currentScrollTop = this.scrollContainer!.scrollTop;
const currentScrollTop = this.scrollContainer.scrollTop;

if (!this._headerSnapped && this.headerPinned) {
this.headerPinned = false;
Expand All @@ -414,16 +418,16 @@ class DynamicPage extends UI5Element {
if (!this._headerSnapped) {
this._headerSnapped = true;
this.showHeaderInStickArea = true;
this.scrollContainer!.scrollTop = 0;
this.scrollContainer.scrollTop = 0;
} else {
this.showHeaderInStickArea = false;
this._headerSnapped = false;
}
return;
}

if (this.scrollContainer!.scrollTop === SCROLL_THRESHOLD) {
this.scrollContainer!.scrollTop = 0;
if (this.scrollContainer.scrollTop === SCROLL_THRESHOLD) {
this.scrollContainer.scrollTop = 0;
}

this.showHeaderInStickArea = !this.showHeaderInStickArea;
Expand All @@ -432,8 +436,8 @@ class DynamicPage extends UI5Element {
this.skipSnapOnScroll = true;

await renderFinished();
if (this._headerSnapped && this.scrollContainer!.scrollTop < SCROLL_THRESHOLD) {
this.scrollContainer!.scrollTop = SCROLL_THRESHOLD;
if (this._headerSnapped && this.scrollContainer.scrollTop < SCROLL_THRESHOLD) {
this.scrollContainer.scrollTop = SCROLL_THRESHOLD;
}
}

Expand Down
Loading