fix : moves panel scroll into view

This commit is contained in:
GuillaumeSD
2024-04-06 03:21:39 +02:00
parent 61d17a6c56
commit 7c3744a74a
2 changed files with 6 additions and 1 deletions

View File

@@ -47,6 +47,7 @@ export default function MovesPanel() {
sx={{ scrollbarWidth: "thin", overflowY: "auto" }} sx={{ scrollbarWidth: "thin", overflowY: "auto" }}
maxHeight="100%" maxHeight="100%"
xs={6} xs={6}
id="moves-panel"
> >
{gameMoves?.map((moves, idx) => ( {gameMoves?.map((moves, idx) => (
<MovesLine <MovesLine

View File

@@ -25,7 +25,11 @@ export default function MoveItem({ san, moveClassification, moveIdx }: Props) {
useEffect(() => { useEffect(() => {
if (!isCurrentMove) return; if (!isCurrentMove) return;
const moveItem = document.getElementById(`move-${moveIdx}`); const moveItem = document.getElementById(`move-${moveIdx}`);
if (!moveItem || !isInViewport(moveItem)) return; if (!moveItem) return;
const movePanel = document.getElementById("moves-panel");
if (!movePanel || !isInViewport(movePanel)) return;
moveItem.scrollIntoView({ behavior: "smooth", block: "center" }); moveItem.scrollIntoView({ behavior: "smooth", block: "center" });
}, [isCurrentMove, moveIdx]); }, [isCurrentMove, moveIdx]);