fix(mental-health): focus the first question once its wording has loaded

Each step focuses its question, but the first step's question only exists
once the language's wording chunk has arrived; the focus ran while the step
still showed its loading state and was never moved again, so a keyboard or
screen reader user started on the page body.
This commit is contained in:
Marc-André Bombeck committed 2026-10-25 09:24:19 +01:00
1 parent 9ff35efb47
commit 4853e9cee6
1 file changed
+13 -4
@@ -67,6 +67,18 @@ interface StepWording {
lang: string;
}
/**
* Each step focuses its question. The first step's question exists only once
* the wording's chunk has loaded, so the focus also follows that.
*/
function useStepFocus(step: number, hasWording: boolean) {
const headingRef = useRef<HTMLHeadingElement | null>(null);
useEffect(() => {
headingRef.current?.focus({ preventScroll: false });
}, [step, hasWording]);
return headingRef;
}
export function CheckInWizard({
instrument,
onSubmit,
@@ -99,10 +111,7 @@ export function CheckInWizard({
const onFunctional = step === steps.functionalStep;
const questionIndex = step - 1;
const headingRef = useRef<HTMLHeadingElement | null>(null);
useEffect(() => {
headingRef.current?.focus({ preventScroll: false });
}, [step]);
const headingRef = useStepFocus(step, Boolean(wording));
function advance() {
if (fromReview && isComplete(items)) {