Fix settings scroll target positioning (#1829)

This commit is contained in:
海雀 authored and GitHub committed 2026-06-22 12:57:26 +02:00
1 parent 7c6151fbe5
commit 064e22dc1a
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'