From 0ac422a70ad4052ec11859d0358016039450ac55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 26 Jun 2024 10:09:33 +0100 Subject: [PATCH 1/2] feat: Scroll new list item into view --- .../src/@planx/components/List/Public/index.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/editor.planx.uk/src/@planx/components/List/Public/index.tsx b/editor.planx.uk/src/@planx/components/List/Public/index.tsx index 44117493dc..66efdcd9d9 100644 --- a/editor.planx.uk/src/@planx/components/List/Public/index.tsx +++ b/editor.planx.uk/src/@planx/components/List/Public/index.tsx @@ -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"; @@ -67,12 +67,19 @@ const ActiveListCard: React.FC<{ }> = ({ index: i }) => { const { schema, saveItem, cancelEditItem, errors, isPageComponent } = useListContext(); - + + const ref = useRef(null); + useEffect(() => { + if (ref.current) { + ref.current.scrollIntoView({ behavior: "smooth" }) + } + }, []); + return ( - + {schema.type} {!isPageComponent && ` ${i + 1}`} From 132e5bc5170ffe9be91f901ab057dd79f540a475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dafydd=20Ll=C5=B7r=20Pearson?= Date: Wed, 26 Jun 2024 11:15:24 +0100 Subject: [PATCH 2/2] fix: Mock scrollIntoView for JSDOM --- editor.planx.uk/src/@planx/components/List/Public/index.test.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx b/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx index aa47784682..2d4ce28ced 100644 --- a/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx +++ b/editor.planx.uk/src/@planx/components/List/Public/index.test.tsx @@ -13,6 +13,7 @@ import { mockMaxOneProps } from "../schemas/mocks/MaxOne"; import { mockZooPayload, mockZooProps } from "../schemas/mocks/Zoo"; jest.setTimeout(20_000); +Element.prototype.scrollIntoView = jest.fn(); describe("Basic UI", () => { it("renders correctly", () => {