Skip to content

Commit

Permalink
fix: Always center flows on load
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Nov 14, 2024
1 parent 1b02cfd commit 021e047
Showing 1 changed file with 14 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { useEffect, useRef } from "react";
import { Link } from "react-navi";
import {
Link,
useCurrentRoute,
useLoadingRoute,
useNavigation,
} from "react-navi";
import scrollIntoView from "scroll-into-view-if-needed";

import { rootFlowPath } from "../../../../../routes/utils";
Expand All @@ -14,24 +19,29 @@ const EndPoint: React.FC<{ text: string }> = ({ text }) => {

const href = rootFlowPath(false);

const currentPath = rootFlowPath(true);
const isLoading = useLoadingRoute();

useEffect(() => {
if (isStart && el.current) {
if (isLoading) return;

scrollIntoView(
el.current,
flowLayout === FlowLayout.TOP_DOWN
? {
scrollMode: "if-needed",
scrollMode: "always",
block: "nearest",
inline: "center",
}
: {
scrollMode: "if-needed",
scrollMode: "always",
block: "center",
inline: "nearest",
},
);
}
}, [flowLayout, isStart]);
}, [flowLayout, isStart, currentPath, isLoading]);

return (
<li
Expand Down

0 comments on commit 021e047

Please sign in to comment.