From cb31f6ed1d296c2e9a498c2b771f39ef0011995f Mon Sep 17 00:00:00 2001 From: Pete <107579368+thiessenp-cds@users.noreply.github.com> Date: Mon, 26 Aug 2024 14:09:37 -0400 Subject: [PATCH] fix: Adds focus heading behavior for forms with pages (groups) (#4201) * Adds scroll top behavior for forms with pages * Updates to use combined DOM and refs for focussing * Updates comments and names * Updates naming * Updates names part 2 --- .../form-builder/[id]/preview/BackButton.tsx | 3 +- .../form-builder/[id]/preview/Preview.tsx | 6 +++- .../forms/BackButtonGroup/BackButtonGroup.tsx | 9 +++++- .../clientComponents/forms/Form/Form.tsx | 15 ++++++++-- .../forms/NextButton/NextButton.tsx | 2 ++ .../clientComponents/forms/Review/Review.tsx | 29 +++++++++++++++---- lib/client/clientHelpers.ts | 16 ++++++++++ 7 files changed, 69 insertions(+), 11 deletions(-) diff --git a/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/BackButton.tsx b/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/BackButton.tsx index 98dda43822..3323535c70 100644 --- a/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/BackButton.tsx +++ b/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/BackButton.tsx @@ -4,7 +4,7 @@ import { Button } from "@clientComponents/forms"; import { Language } from "@lib/types/form-builder-types"; // Must be placed withing context of the GCFormsContext.Provider -export const BackButton = ({ language }: { language: Language }) => { +export const BackButton = ({ language, onClick }: { language: Language; onClick?: () => void }) => { const { t } = useTranslation("review"); const { setGroup, previousGroup } = useGCFormsContext(); return ( @@ -13,6 +13,7 @@ export const BackButton = ({ language }: { language: Language }) => { secondary={true} onClick={() => { setGroup(previousGroup); + onClick && onClick(); }} > {t("goBack", { lng: language })} diff --git a/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/Preview.tsx b/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/Preview.tsx index 0ec464b7a7..0d5d94dd08 100644 --- a/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/Preview.tsx +++ b/app/(gcforms)/[locale]/(form administration)/form-builder/[id]/preview/Preview.tsx @@ -27,6 +27,7 @@ import { ErrorSaving } from "@formBuilder/components/shared/ErrorSaving"; import { toast } from "@formBuilder/components/shared"; import { defaultForm } from "@lib/store/defaults"; import { showReviewPage } from "@lib/utils/form-builder/showReviewPage"; +import { focusElement } from "@lib/client/clientHelpers"; export const Preview = ({ disableSubmit = true, @@ -209,7 +210,10 @@ export const Preview = ({ return ( <> {allowGrouping && isShowReviewPage && ( - + focusElement("h2")} + /> )}