{Array.isArray(reviewItems) &&
reviewItems.map((reviewItem) => {
@@ -159,14 +162,26 @@ export const Review = ({ language }: { language: Language }): React.ReactElement
className="mb-10 rounded-lg border-2 border-slate-400 px-6 py-4"
>
-
+ {
+ groupsHeadingRef.current?.focus();
+ }}
+ >
{title}
-
+ {
+ groupsHeadingRef.current?.focus();
+ }}
+ >
{t("edit", { lng: language })}
@@ -233,10 +248,12 @@ const EditButton = ({
reviewItem,
theme,
children,
+ onClick,
}: {
reviewItem: ReviewItem;
theme: Theme;
children: React.ReactElement | string;
+ onClick?: () => void;
}): React.ReactElement => {
const { setGroup, clearHistoryAfterId } = useGCFormsContext();
return (
@@ -246,6 +263,8 @@ const EditButton = ({
onClick={() => {
setGroup(reviewItem.id);
clearHistoryAfterId(reviewItem.id);
+ // Focus groups heading on navigation
+ onClick && onClick();
}}
>
{children}
diff --git a/lib/client/clientHelpers.ts b/lib/client/clientHelpers.ts
index 4483aba614..72c7a9c92f 100644
--- a/lib/client/clientHelpers.ts
+++ b/lib/client/clientHelpers.ts
@@ -20,6 +20,22 @@ export const scrollToBottom = (containerEl: HTMLElement) => {
}
};
+/**
+ * When a function does not have access to an element (ref), use the DOM to get an element and
+ * after the next tick (after the current event loop), focus the element. This moves the page to
+ * the element location and announces the text in the element to AT. Use a react ref over this to
+ * get and focus an element when possible.
+ * @param elementSelector selector to get the DOM element (first one found). Defaults to H1. Must
+ * have a tabIndex.
+ * @returns undefined
+ */
+export const focusElement = (elementSelector = "H1") => {
+ const NEXT_TICK = 0;
+ setTimeout(() => {
+ (document.querySelector(elementSelector) as HTMLElement)?.focus();
+ }, NEXT_TICK);
+};
+
/**
* Like a UUID but smaller and not as unique. So best to append this to the element name.
* e.g. id = `myElementName-${randomId()}`