Fixed anchoring

This commit is contained in:
2023-08-31 00:23:12 +02:00
parent 62f54d4f16
commit cbc4d839d0
2 changed files with 7 additions and 3 deletions

View File

@@ -1,8 +1,8 @@
import * as React from "react";
import {useEffect, useRef, useState} from "react";
import {tinaField} from "tinacms/dist/react";
import {Template} from "tinacms";
import {ObjectField} from "@tinacms/schema-tools/dist/types";
import {SectionElement} from "@react-types/shared";
interface AnchoringProps {
text?: string, // Default: Découvrez-en plus !
@@ -11,7 +11,7 @@ interface AnchoringProps {
export const Anchoring = (props: AnchoringProps) => {
const [opacity, setOpacity] = useState(1);
const anchoringRef = useRef(null);
const anchoringRef = useRef<HTMLDivElement>(null);
const handleScrollOpacity = () => {
const scrollTop = window.scrollY || window.pageYOffset;
@@ -21,7 +21,8 @@ export const Anchoring = (props: AnchoringProps) => {
};
const handleScrollClick = () => {
anchoringRef?.current?.scrollIntoView({
const nextSection = anchoringRef?.current?.closest("section")?.parentElement?.nextElementSibling;
nextSection?.scrollIntoView({
behavior: "smooth",
block: "start"
});