Skip to content

Commit

Permalink
feat: Scroll new list item into view
Browse files Browse the repository at this point in the history
  • Loading branch information
DafyddLlyr committed Jun 26, 2024
1 parent be6a176 commit 0ac422a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions editor.planx.uk/src/@planx/components/List/Public/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import TableCell from "@mui/material/TableCell";
import TableRow from "@mui/material/TableRow";
import Typography from "@mui/material/Typography";
import { PublicProps } from "@planx/components/ui";
import React from "react";
import React, { useEffect, useRef } from "react";
import { FONT_WEIGHT_SEMI_BOLD } from "theme";
import ErrorWrapper from "ui/shared/ErrorWrapper";
import InputRow from "ui/shared/InputRow";
Expand Down Expand Up @@ -67,12 +67,19 @@ const ActiveListCard: React.FC<{
}> = ({ index: i }) => {
const { schema, saveItem, cancelEditItem, errors, isPageComponent } =
useListContext();


const ref = useRef<HTMLDivElement>(null);
useEffect(() => {
if (ref.current) {
ref.current.scrollIntoView({ behavior: "smooth" })
}
}, []);

return (
<ErrorWrapper
error={errors.unsavedItem ? "Please save in order to continue" : ""}
>
<ListCard data-testid={`list-card-${i}`}>
<ListCard data-testid={`list-card-${i}`} ref={ref}>
<Typography component="h2" variant="h3">
{schema.type}
{!isPageComponent && ` ${i + 1}`}
Expand Down

0 comments on commit 0ac422a

Please sign in to comment.