mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-10 21:32:18 +00:00
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:
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)) {
|
||||
|
||||
Reference in new issue
Block a user