Skip to content
Snippets Groups Projects
Commit 2f86fc5e authored by Les Orchard's avatar Les Orchard Committed by Eugen Rochko
Browse files

Identify manual scrolling to cancel scroll to top reset on mouse idle (#9245)

parent 08b3de4d
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,13 @@ export default class ScrollableList extends PureComponent {
} else if (this.props.onScroll) {
this.props.onScroll();
}
if (!this.lastScrollWasSynthetic) {
// If the last scroll wasn't caused by setScrollTop(), assume it was
// intentional and cancel any pending scroll reset on mouse idle
this.scrollToTopOnMouseIdle = false;
}
this.lastScrollWasSynthetic = false;
}
}, 150, {
trailing: true,
......@@ -66,8 +73,16 @@ export default class ScrollableList extends PureComponent {
mouseIdleTimer = null;
mouseMovedRecently = false;
lastScrollWasSynthetic = false;
scrollToTopOnMouseIdle = false;
setScrollTop = newScrollTop => {
if (this.node.scrollTop !== newScrollTop) {
this.lastScrollWasSynthetic = true;
this.node.scrollTop = newScrollTop;
}
};
clearMouseIdleTimer = () => {
if (this.mouseIdleTimer === null) {
return;
......@@ -99,7 +114,7 @@ export default class ScrollableList extends PureComponent {
handleMouseIdle = () => {
if (this.scrollToTopOnMouseIdle) {
this.node.scrollTop = 0;
this.setScrollTop(0);
}
this.mouseMovedRecently = false;
......@@ -132,11 +147,7 @@ export default class ScrollableList extends PureComponent {
// Reset the scroll position when a new child comes in in order not to
// jerk the scrollbar around if you're already scrolled down the page.
if (snapshot !== null) {
const newScrollTop = this.node.scrollHeight - snapshot;
if (this.node.scrollTop !== newScrollTop) {
this.node.scrollTop = newScrollTop;
}
this.setScrollTop(this.node.scrollHeight - snapshot);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment