taler-typescript-core

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

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

anastasis web UI: focus setup fields when they open

Use shared focus requests for input components and start continent,
policy and email setup on their first control.

Issue: https://bugs.taler.net/n/12061
Issue: https://bugs.taler.net/n/12062
Issue: https://bugs.taler.net/n/12063
Assisted-by: LLM

Diffstat:
Mpackages/anastasis-webui/src/components/fields/DateInput.tsx | 13+++++++------
Mpackages/anastasis-webui/src/components/fields/EmailInput.tsx | 13+++++++------
Mpackages/anastasis-webui/src/components/fields/FileInput.tsx | 13+++++++------
Mpackages/anastasis-webui/src/components/fields/NumberInput.tsx | 13+++++++------
Mpackages/anastasis-webui/src/components/fields/TextInput.tsx | 10++++------
Mpackages/anastasis-webui/src/pages/home/ContinentSelectionScreen.tsx | 7++++++-
Mpackages/anastasis-webui/src/pages/home/EditPoliciesScreen.tsx | 7++++++-
Mpackages/anastasis-webui/src/pages/home/authMethod/AuthMethodEmailSetup.tsx | 1+
8 files changed, 45 insertions(+), 32 deletions(-)

diff --git a/packages/anastasis-webui/src/components/fields/DateInput.tsx b/packages/anastasis-webui/src/components/fields/DateInput.tsx @@ -13,10 +13,12 @@ You should have received a copy of the GNU Affero General Public License along with GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { i18n } from "@gnu-taler/taler-util"; import { format, subYears } from "date-fns"; import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; import { DatePicker } from "../picker/DatePicker.js"; import { useTranslationContext } from "../../context/translation.js"; @@ -33,11 +35,10 @@ export interface DateInputProps { export function DateInput(props: DateInputProps): VNode { const { lang } = useTranslationContext(); const inputRef = useRef<HTMLInputElement>(null); - useLayoutEffect(() => { - if (props.grabFocus) { - inputRef.current?.focus(); - } - }, [props.grabFocus]); + useFocusScope({ + active: !!props.grabFocus, + initialFocus: () => inputRef.current, + }); const [opened, setOpened] = useState(false); const value = props.bind[0] || ""; diff --git a/packages/anastasis-webui/src/components/fields/EmailInput.tsx b/packages/anastasis-webui/src/components/fields/EmailInput.tsx @@ -13,8 +13,10 @@ You should have received a copy of the GNU Affero General Public License along with GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; export interface TextInputProps { label: string; @@ -28,11 +30,10 @@ export interface TextInputProps { export function EmailInput(props: TextInputProps): VNode { const inputRef = useRef<HTMLInputElement>(null); - useLayoutEffect(() => { - if (props.grabFocus) { - inputRef.current?.focus(); - } - }, [props.grabFocus]); + useFocusScope({ + active: !!props.grabFocus, + initialFocus: () => inputRef.current, + }); const value = props.bind[0]; const [dirty, setDirty] = useState(false); const showError = dirty && props.error; diff --git a/packages/anastasis-webui/src/components/fields/FileInput.tsx b/packages/anastasis-webui/src/components/fields/FileInput.tsx @@ -18,9 +18,11 @@ * * @author Sebastian Javier Marchano (sebasjm) */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { i18n } from "@gnu-taler/taler-util"; import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; const MAX_IMAGE_UPLOAD_SIZE = 1024 * 1024; @@ -42,11 +44,10 @@ export interface FileInputProps { export function FileInput(props: FileInputProps): VNode { const inputRef = useRef<HTMLInputElement>(null); - useLayoutEffect(() => { - if (props.grabFocus) { - inputRef.current?.focus(); - } - }, [props.grabFocus]); + useFocusScope({ + active: !!props.grabFocus, + initialFocus: () => inputRef.current, + }); const fileInputRef = useRef<HTMLInputElement>(null); const [sizeError, setSizeError] = useState(false); diff --git a/packages/anastasis-webui/src/components/fields/NumberInput.tsx b/packages/anastasis-webui/src/components/fields/NumberInput.tsx @@ -13,8 +13,10 @@ You should have received a copy of the GNU Affero General Public License along with GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; export interface TextInputProps { label: string; @@ -28,11 +30,10 @@ export interface TextInputProps { export function PhoneNumberInput(props: TextInputProps): VNode { const inputRef = useRef<HTMLInputElement>(null); - useLayoutEffect(() => { - if (props.grabFocus) { - inputRef.current?.focus(); - } - }, [props.grabFocus]); + useFocusScope({ + active: !!props.grabFocus, + initialFocus: () => inputRef.current, + }); const value = props.bind[0]; const [dirty, setDirty] = useState(false); const showError = dirty && props.error; diff --git a/packages/anastasis-webui/src/components/fields/TextInput.tsx b/packages/anastasis-webui/src/components/fields/TextInput.tsx @@ -13,8 +13,10 @@ You should have received a copy of the GNU Affero General Public License along with GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { h, VNode } from "preact"; -import { useLayoutEffect, useRef, useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; export interface TextInputProps { inputType?: "text" | "number" | "multiline" | "password"; @@ -30,11 +32,7 @@ export interface TextInputProps { const TextInputType = function ({ inputType, grabFocus, ...rest }: any): VNode { const inputRef = useRef<HTMLInputElement>(null); - useLayoutEffect(() => { - if (grabFocus) { - inputRef.current?.focus(); - } - }, [grabFocus]); + useFocusScope({ active: !!grabFocus, initialFocus: () => inputRef.current }); return inputType === "multiline" ? ( <textarea {...rest} rows={5} ref={inputRef} style={{ height: "unset" }} /> diff --git a/packages/anastasis-webui/src/pages/home/ContinentSelectionScreen.tsx b/packages/anastasis-webui/src/pages/home/ContinentSelectionScreen.tsx @@ -13,9 +13,11 @@ You should have received a copy of the GNU Affero General Public License along with GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { i18n } from "@gnu-taler/taler-util"; import { h, VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; import { useAnastasisContext } from "../../context/anastasis.js"; import { useTranslationContext } from "../../context/translation.js"; import { AnastasisClientFrame, withProcessLabel } from "./index.js"; @@ -28,6 +30,8 @@ export function ContinentSelectionScreen(): VNode { const countryFromReducer = (reducer?.currentReducerState as any).selected_country || ""; const [countryCode, setCountryCode] = useState(countryFromReducer); + const continentRef = useRef<HTMLSelectElement>(null); + useFocusScope({ initialFocus: () => continentRef.current }); if ( !reducer || @@ -87,6 +91,7 @@ export function ContinentSelectionScreen(): VNode { <div class="select is-fullwidth"> <select id="continent-selection" + ref={continentRef} onChange={(e) => selectContinent(e.currentTarget.value)} value={theContinent} > diff --git a/packages/anastasis-webui/src/pages/home/EditPoliciesScreen.tsx b/packages/anastasis-webui/src/pages/home/EditPoliciesScreen.tsx @@ -13,9 +13,11 @@ You should have received a copy of the GNU Affero General Public License along with GNU Anastasis; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ + +import { useFocusScope } from "@gnu-taler/web-util/browser"; import { i18n } from "@gnu-taler/taler-util"; import { h, VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; import { useAnastasisContext } from "../../context/anastasis.js"; import { authMethods, KnownAuthMethods } from "./authMethod/index.js"; import { AnastasisClientFrame } from "./index.js"; @@ -47,6 +49,8 @@ export function EditPoliciesScreen({ confirm, }: Props): VNode { const [changedProvider, setChangedProvider] = useState<Array<string>>([]); + const firstSelectRef = useRef<HTMLSelectElement>(null); + useFocusScope({ initialFocus: () => firstSelectRef.current }); const reducer = useAnastasisContext(); if (!reducer) { @@ -154,6 +158,7 @@ export function EditPoliciesScreen({ <span> <span class="select "> <select + ref={index === 0 ? firstSelectRef : undefined} onChange={(e) => changeProviderTo(e.currentTarget.value)} value={providerURL ?? ""} > diff --git a/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodEmailSetup.tsx b/packages/anastasis-webui/src/pages/home/authMethod/AuthMethodEmailSetup.tsx @@ -58,6 +58,7 @@ export function AuthMethodEmailSetup({ <div> <EmailInput label={i18n.str`Email address`} + grabFocus error={emailError} onConfirm={goNextIfNoErrors} placeholder={i18n.str`email@domain.com`}