mirror of
https://github.com/Buriburizaem0n/nezha-dash-v1.git
synced 2026-09-19 17:50:13 +00:00
Implement scroll position management for navigation (#73)
* feat: implement scroll position management for main page navigation * fix: import saveMainPageScrollPosition in ServerCard and ServerCardInline components * feat: save scroll position when navigating to server from DashCommand * fix: prevent restoring stale scroll positions without main page origin
This commit is contained in:
@@ -59,13 +59,22 @@ export default function GroupSwitch({
|
||||
|
||||
useEffect(() => {
|
||||
const currentTagRef = itemRefs.current[tabs.indexOf(currentTab)];
|
||||
const scrollContainer = scrollRef.current;
|
||||
|
||||
if (currentTagRef) {
|
||||
currentTagRef.scrollIntoView({
|
||||
behavior: "smooth",
|
||||
block: "nearest",
|
||||
inline: "center",
|
||||
});
|
||||
if (currentTagRef && scrollContainer) {
|
||||
const nextScrollLeft =
|
||||
currentTagRef.offsetLeft -
|
||||
scrollContainer.clientWidth / 2 +
|
||||
currentTagRef.offsetWidth / 2;
|
||||
|
||||
if (typeof scrollContainer.scrollTo === "function") {
|
||||
scrollContainer.scrollTo({
|
||||
behavior: "smooth",
|
||||
left: Math.max(0, nextScrollLeft),
|
||||
});
|
||||
} else {
|
||||
scrollContainer.scrollLeft = Math.max(0, nextScrollLeft);
|
||||
}
|
||||
}
|
||||
}, [currentTab, itemRefs, tabs]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user