fix: scroll to top in settings

fixes #108
This commit is contained in:
Paul 2021-11-14 19:18:37 +00:00
parent b2a222d7e8
commit 74e786053e

View file

@ -5,7 +5,13 @@ import { useHistory, useParams } from "react-router-dom";
import styles from "./Settings.module.scss"; import styles from "./Settings.module.scss";
import classNames from "classnames"; import classNames from "classnames";
import { Text } from "preact-i18n"; import { Text } from "preact-i18n";
import { useCallback, useContext, useEffect, useState } from "preact/hooks"; import {
useCallback,
useContext,
useEffect,
useRef,
useState,
} from "preact/hooks";
import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice"; import { isTouchscreenDevice } from "../../lib/isTouchscreenDevice";
@ -74,6 +80,8 @@ export function GenericSettings({
return () => document.body.removeEventListener("keydown", keyDown); return () => document.body.removeEventListener("keydown", keyDown);
}, [exitSettings]); }, [exitSettings]);
const pageRef = useRef<string>();
return ( return (
<div <div
className={classNames(styles.settings, { className={classNames(styles.settings, {
@ -155,7 +163,17 @@ export function GenericSettings({
)} )}
{(!isTouchscreenDevice || typeof page === "string") && ( {(!isTouchscreenDevice || typeof page === "string") && (
<div className={styles.content}> <div className={styles.content}>
<div className={styles.scrollbox}> <div
className={styles.scrollbox}
ref={(ref) => {
// Force scroll to top if page changes.
if (ref) {
if (pageRef.current !== page) {
ref.scrollTop = 0;
pageRef.current = page;
}
}
}}>
<div className={styles.contentcontainer}> <div className={styles.contentcontainer}>
{!isTouchscreenDevice && {!isTouchscreenDevice &&
!pages.find( !pages.find(