taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit fb42fd4355e0f9dc8380fcdee369a640fce00ee8
parent 66a3f3f16c0dde2feda831e29101ee60ba8ad656
Author: Florian Dold <dold@taler.net>
Date:   Fri, 13 Nov 2026 01:06:16 +0100

challenger web UI: focus address and code steps once

Focus the first editable setup or address field. Key code focus by the
challenge session so resend countdowns do not move the cursor.

Issue: https://bugs.taler.net/n/12043
Issue: https://bugs.taler.net/n/12044
Issue: https://bugs.taler.net/n/12045
Assisted-by: LLM

Diffstat:
Mpackages/challenger-webui/src/Routing.tsx | 1+
Mpackages/challenger-webui/src/pages/AnswerChallenge.tsx | 12++++++++----
Mpackages/challenger-webui/src/pages/AskChallenge.tsx | 1+
Mpackages/challenger-webui/src/pages/Setup.tsx | 23+++++++++++++++++++++--
4 files changed, 31 insertions(+), 6 deletions(-)

diff --git a/packages/challenger-webui/src/Routing.tsx b/packages/challenger-webui/src/Routing.tsx @@ -137,6 +137,7 @@ function PublicRouting(): VNode { return ( <Setup + focus clientId={safeDecodeURIComponent(location.values.client)} secret={secret} redirectURL={redirectURL} diff --git a/packages/challenger-webui/src/pages/AnswerChallenge.tsx b/packages/challenger-webui/src/pages/AnswerChallenge.tsx @@ -6,6 +6,8 @@ terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { AbsoluteTime, ChallengerApi, @@ -86,6 +88,11 @@ export function AnswerChallenge({ const [deliveryErrorDetails, setDeliveryErrorDetails] = useState<string>(); const [newCodeSent, setNewCodeSent] = useState(false); const pinInput = useRef<HTMLInputElement | null>(null); + useFocusScope({ + active: !!focus, + activationKey: `${session.clientId}:${session.nonce}`, + initialFocus: () => pinInput.current, + }); const { result, retry, isRefreshing } = useChallengeSession(session); const lastStatus = @@ -381,10 +388,7 @@ export function AnswerChallenge({ {verificationCodeLabel} </label> <input - ref={(element) => { - pinInput.current = element; - if (focus) doAutoFocus(element); - }} + ref={pinInput} id="pin" name="pin" type="text" diff --git a/packages/challenger-webui/src/pages/AskChallenge.tsx b/packages/challenger-webui/src/pages/AskChallenge.tsx @@ -576,6 +576,7 @@ function AskChallengeInternal({ <FormUI design={design} model={form.model} + focus={focus} onSubmit={sendArgs ? () => send.run(...sendArgs) : undefined} /> </div> diff --git a/packages/challenger-webui/src/pages/Setup.tsx b/packages/challenger-webui/src/pages/Setup.tsx @@ -6,6 +6,9 @@ terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version. */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; +import { useRef } from "preact/hooks"; import { AccessToken, HttpStatusCode, @@ -30,7 +33,7 @@ import { TechnicalDetails, VerificationCard, } from "../components/VerificationUi.js"; -import { doAutoFocus, undefinedIfEmpty } from "./AnswerChallenge.js"; +import { undefinedIfEmpty } from "./AnswerChallenge.js"; type Props = { clientId: string; @@ -85,6 +88,22 @@ export function Setup({ clientId, secret, redirectURL, focus }: Props): VNode { ? invalidUrlMessage : undefined, }); + // Values passed in the URL are read-only; start on the first field the + // developer still has to fill in. + const focusField = !focus + ? undefined + : secret === undefined + ? "password" + : redirectURL === undefined + ? "redirect_url" + : undefined; + const setupForm = useRef<HTMLDivElement>(null); + useFocusScope({ + active: !!focus, + root: () => setupForm.current, + initialFocus: () => + setupForm.current?.querySelector<HTMLElement>(`[id="${focusField}"]`), + }); const startArgs = errors || !password || !url ? undefined @@ -128,6 +147,7 @@ export function Setup({ clientId, secret, redirectURL, focus }: Props): VNode { } > <form + ref={setupForm as any} onSubmit={(event) => { event.preventDefault(); if (startArgs) void start.run(...startArgs); @@ -138,7 +158,6 @@ export function Setup({ clientId, secret, redirectURL, focus }: Props): VNode { {clientPasswordLabel} </label> <input - ref={focus ? doAutoFocus : undefined} id="password" name="password" type="password"