mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix: Fixes top level tabs and automatic scroll (#14624)
(cherry picked from commit 9cb4a4602f)
This commit is contained in:
committed by
henryyeh
parent
c5637dba34
commit
2da0c347db
@@ -20,22 +20,34 @@ let scrollTopDashboardInterval: any;
|
||||
const SCROLL_STEP = 120;
|
||||
const INTERVAL_DELAY = 50;
|
||||
|
||||
export default function handleScroll(dropPosition: string) {
|
||||
if (dropPosition === 'SCROLL_TOP') {
|
||||
if (!scrollTopDashboardInterval) {
|
||||
scrollTopDashboardInterval = setInterval(() => {
|
||||
let scrollTop = document.documentElement.scrollTop - SCROLL_STEP;
|
||||
if (scrollTop < 0) {
|
||||
scrollTop = 0;
|
||||
}
|
||||
window.scroll({
|
||||
top: scrollTop,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}, INTERVAL_DELAY);
|
||||
}
|
||||
}
|
||||
if (dropPosition !== 'SCROLL_TOP' && scrollTopDashboardInterval) {
|
||||
export default function handleScroll(scroll: string) {
|
||||
const setupScroll =
|
||||
scroll === 'SCROLL_TOP' &&
|
||||
!scrollTopDashboardInterval &&
|
||||
document.documentElement.scrollTop !== 0;
|
||||
|
||||
const clearScroll =
|
||||
scrollTopDashboardInterval &&
|
||||
(scroll !== 'SCROLL_TOP' || document.documentElement.scrollTop === 0);
|
||||
|
||||
if (setupScroll) {
|
||||
scrollTopDashboardInterval = setInterval(() => {
|
||||
if (document.documentElement.scrollTop === 0) {
|
||||
clearInterval(scrollTopDashboardInterval);
|
||||
scrollTopDashboardInterval = null;
|
||||
return;
|
||||
}
|
||||
|
||||
let scrollTop = document.documentElement.scrollTop - SCROLL_STEP;
|
||||
if (scrollTop < 0) {
|
||||
scrollTop = 0;
|
||||
}
|
||||
window.scroll({
|
||||
top: scrollTop,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}, INTERVAL_DELAY);
|
||||
} else if (clearScroll) {
|
||||
clearInterval(scrollTopDashboardInterval);
|
||||
scrollTopDashboardInterval = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user