mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-27 12:26:33 -08:00
Fix settings scroll target positioning (#1829)
This commit is contained in:
2 files changed
+9
-17
No files matched your search
@@ -1,7 +1,6 @@
|
||||
import classNames from 'classnames';
|
||||
import { ReactNode, useEffect, useRef } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { useBreakpoint } from '@/hooks/breakpoint';
|
||||
|
||||
export function SettingsPageLayout({
|
||||
children,
|
||||
@@ -12,7 +11,6 @@ export function SettingsPageLayout({
|
||||
} & React.HTMLAttributes<HTMLDivElement>) {
|
||||
const pageRef = useRef<HTMLDivElement | null>(null);
|
||||
const { state } = useLocation();
|
||||
const { isMobile } = useBreakpoint('mobile');
|
||||
|
||||
useEffect(() => {
|
||||
const typedState: { scrollTo: string } = state;
|
||||
@@ -23,19 +21,10 @@ export function SettingsPageLayout({
|
||||
`#${typedState.scrollTo}`
|
||||
) as HTMLElement | null;
|
||||
if (elem) {
|
||||
// stupid way of doing this, just get the closest overflow-y-auto
|
||||
// usually its just the parentElem
|
||||
const closestScroll = elem.closest(
|
||||
'.overflow-y-auto'
|
||||
) as HTMLElement | null;
|
||||
if (closestScroll) {
|
||||
// The 45 is just enough padding for making the scroll look perfect
|
||||
const topPadding = isMobile ? 80 : 45;
|
||||
closestScroll.scroll({
|
||||
top: elem.offsetTop - topPadding,
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}
|
||||
elem.scrollIntoView({
|
||||
block: 'start',
|
||||
behavior: 'smooth',
|
||||
});
|
||||
}
|
||||
}, [state]);
|
||||
|
||||
@@ -58,7 +47,7 @@ export function SettingsPagePaneLayout({
|
||||
return (
|
||||
<div
|
||||
className={classNames(
|
||||
'bg-background-70 rounded-lg px-4 py-8 flex xs:gap-4 w-full relative',
|
||||
'bg-background-70 rounded-lg px-4 py-8 flex xs:gap-4 w-full relative scroll-mt-12 mobile:scroll-mt-20',
|
||||
className
|
||||
)}
|
||||
{...props}
|
||||
|
||||
@@ -94,7 +94,10 @@ export function MagnetometerToggleSetting({
|
||||
|
||||
return settingType === 'general' ? (
|
||||
<>
|
||||
<div className="flex flex-col pt-5 pb-3" id={id}>
|
||||
<div
|
||||
className="flex flex-col pt-5 pb-3 scroll-mt-12 mobile:scroll-mt-20"
|
||||
id={id}
|
||||
>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString(
|
||||
'settings-general-tracker_mechanics-use_mag_on_all_trackers'
|
||||
|
||||
Reference in new issue
Block a user