Skip to content

Commit

Permalink
MudScrollToTop: Fix Exception When Changing Page (MudBlazor#5060)
Browse files Browse the repository at this point in the history
  • Loading branch information
ScarletKuro authored and jammerware committed Sep 20, 2022
1 parent 5d6f963 commit 66161dd
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/MudBlazor/TScripts/mudScrollListener.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class MudScrollListener {

constructor() {
this.throttleScrollHandlerId = -1;
//needed as variable to remove the event listeners
this.handlerRef = null;
}

// subscribe to throttled scroll event
Expand All @@ -16,10 +18,11 @@ class MudScrollListener {
? document.querySelector(selector)
: document;

this.handlerRef = this.throttleScrollHandler.bind(this, dotnetReference);
// add the event listener
element.addEventListener(
'scroll',
this.throttleScrollHandler.bind(this, dotnetReference),
this.handlerRef,
false
);
}
Expand Down Expand Up @@ -54,7 +57,6 @@ class MudScrollListener {
//data to pass
let firstChild = element.firstElementChild;
let firstChildBoundingClientRect = firstChild.getBoundingClientRect();

//invoke C# method
dotnetReference.invokeMethodAsync('RaiseOnScroll', {
firstChildBoundingClientRect,
Expand All @@ -73,9 +75,9 @@ class MudScrollListener {
cancelListener(selector) {
let element = selector
? document.querySelector(selector)
: document.documentElement;
: document;

element.removeEventListener('scroll', this.throttleScrollHandler);
element.removeEventListener('scroll', this.handlerRef);
}
};
window.mudScrollListener = new MudScrollListener();

0 comments on commit 66161dd

Please sign in to comment.