taler-typescript-core

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

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

merchant web UI: use shared focus handling for custom dialogs

Move pairing, account removal, order deletion and template overlays to
Modal. Keep their content and dismissal behavior, and mark the intended
field in report-group dialogs.

Issue: https://bugs.taler.net/n/12005
Issue: https://bugs.taler.net/n/12018
Issue: https://bugs.taler.net/n/12019
Issue: https://bugs.taler.net/n/12020
Issue: https://bugs.taler.net/n/12021
Assisted-by: LLM

Diffstat:
Mpackages/taler-merchant-webui/src/screens/AccessScreen.tsx | 39+++++++++++++++++++++++++++------------
Mpackages/taler-merchant-webui/src/screens/MoneyInScreen.tsx | 28+++++++++++++++++-----------
Mpackages/taler-merchant-webui/src/screens/OrderDetailScreen.tsx | 26++++++++++++++++----------
Mpackages/taler-merchant-webui/src/screens/ReportsScreen.tsx | 2++
Mpackages/taler-merchant-webui/src/screens/TemplatesScreen.tsx | 58+++++++++++++++++++++++++++++-----------------------------
5 files changed, 91 insertions(+), 62 deletions(-)

diff --git a/packages/taler-merchant-webui/src/screens/AccessScreen.tsx b/packages/taler-merchant-webui/src/screens/AccessScreen.tsx @@ -14,9 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Modal } from "../ui/Modal.js"; + import { FormActionFooter, useFormFeedback } from "../ui/FormActionFooter.js"; import type { VNode } from "preact"; -import { useEffect, useState } from "preact/hooks"; +import { useEffect, useRef, useState } from "preact/hooks"; import { useLocation } from "wouter-preact"; import { Header } from "../ui/Header.js"; import { TalerQrCode } from "../ui/TalerQrCode.js"; @@ -134,6 +136,13 @@ export function AccessScreen({ setPairingError(undefined); }, [issuedPairingCredential, setPairingError]); + // This dialog is drawn here rather than by Modal, so it places focus itself: + // in the device name when it opens, and on the heading of the credential + // step, whose arrival removes the focused form and would otherwise drop + // focus to the page, out of reach of the dialog's Escape handler. + const pairNameInput = useRef<HTMLInputElement>(null); + const pairQrHeading = useRef<HTMLHeadingElement>(null); + const displayTokens = tokensResource?.data ?? propTokens ?? []; const isInitiallyLoading = tokensResource?.isLoading === true && tokensResource.data === undefined; @@ -452,15 +461,16 @@ export function AccessScreen({ {/* Pair a till or Point-of-Sale App Modal (Spec 02 § 2.6.2) */} {showPairModal && ( - // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- a dialog closing on Escape is the pattern the rule exists to ask for; it just does not count `dialog` as interactive. - <div - role="dialog" - aria-modal="true" - tabIndex={-1} - onKeyDown={(e) => { - if (e.key === "Escape") handlePairingCloseRequest(); - }} - class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50" + <Modal + activationKey={pairStep} + isOpen + bare + onClose={handlePairingCloseRequest} + initialFocus={() => + pairStep === "form" ? pairNameInput.current : pairQrHeading.current + } + ariaLabel={t`Pair a till`} + overlayClass="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50" > <div class="bg-white rounded-2xl max-w-md w-full p-6 shadow-xl space-y-4 text-left max-h-[90dvh] overflow-y-auto"> {pairStep === "form" ? ( @@ -484,6 +494,7 @@ export function AccessScreen({ {t`Device Name`} <span class="text-red-500">*</span> </label> <input + ref={pairNameInput} id="pair_dev_name" type="text" required @@ -606,7 +617,11 @@ export function AccessScreen({ ) : ( <div class="space-y-4 text-center"> <div> - <h3 class="text-lg font-bold text-gray-900">{t`Scan this with the till app`}</h3> + <h3 + ref={pairQrHeading} + tabIndex={-1} + class="text-lg font-bold text-gray-900 focus:outline-none" + >{t`Scan this with the till app`}</h3> <p class="text-xs text-gray-600 mt-1 leading-relaxed bg-amber-50 p-2 rounded border border-amber-200"> {t`ℹ️ This credential is shown once. Anyone who has it can use the granted till access.`} </p> @@ -695,7 +710,7 @@ export function AccessScreen({ </div> )} </div> - </div> + </Modal> )} </div> ); diff --git a/packages/taler-merchant-webui/src/screens/MoneyInScreen.tsx b/packages/taler-merchant-webui/src/screens/MoneyInScreen.tsx @@ -14,8 +14,10 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Modal } from "../ui/Modal.js"; + import type { VNode } from "preact"; -import { useState } from "preact/hooks"; +import { useRef, useState } from "preact/hooks"; import { TalerMerchantApi } from "@gnu-taler/taler-util"; import { BankMonitoringDialog } from "./BankMonitoringDialog.js"; import { Header } from "../ui/Header.js"; @@ -191,6 +193,10 @@ export function MoneyInScreen({ >(undefined); const [isDeletingAccount, setIsDeletingAccount] = useState<boolean>(false); const [deleteAccountError, setDeleteAccountError] = useState<unknown>(); + // Open the confirmation on its safe choice. The dialog only hears Escape + // while focus is inside it, and the account menu that opens it unmounts the + // control that had focus. + const deleteAccountCancel = useRef<HTMLButtonElement>(null); const [openAccountMenuId, setOpenAccountMenuId] = useState< string | undefined >(undefined); @@ -1299,16 +1305,15 @@ export function MoneyInScreen({ )} {/* Delete Account Modal */} {deletingAccount && ( - // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- a dialog closing on Escape is the pattern the rule exists to ask for; it just does not count `dialog` as interactive. - <div - role="dialog" - aria-modal="true" - tabIndex={-1} - onKeyDown={(e) => { - if (e.key === "Escape" && !isDeletingAccount) - setDeletingAccount(undefined); + <Modal + isOpen + bare + onClose={() => { + if (!isDeletingAccount) setDeletingAccount(undefined); }} - class="fixed inset-0 bg-gray-900/50 backdrop-blur-xs flex items-center justify-center p-4 z-50" + initialFocus={() => deleteAccountCancel.current} + ariaLabel={t`Remove bank account`} + overlayClass="fixed inset-0 bg-gray-900/50 backdrop-blur-xs flex items-center justify-center p-4 z-50" > <div class="bg-white rounded-xl max-w-md w-full p-6 space-y-4 shadow-xl border border-gray-200"> <h3 class="font-bold text-red-900 text-base flex items-center space-x-2"> @@ -1329,6 +1334,7 @@ export function MoneyInScreen({ /> <div class="flex justify-end space-x-2 pt-2"> <button + ref={deleteAccountCancel} type="button" onClick={() => { setDeletingAccount(undefined); @@ -1362,7 +1368,7 @@ export function MoneyInScreen({ </button> </div> </div> - </div> + </Modal> )} </div> ); diff --git a/packages/taler-merchant-webui/src/screens/OrderDetailScreen.tsx b/packages/taler-merchant-webui/src/screens/OrderDetailScreen.tsx @@ -14,9 +14,11 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Modal } from "../ui/Modal.js"; + import { useLocation } from "wouter-preact"; import type { VNode } from "preact"; -import { useEffect, useState } from "preact/hooks"; +import { useEffect, useRef, useState } from "preact/hooks"; import { Header } from "../ui/Header.js"; import { TalerQrCode } from "../ui/TalerQrCode.js"; import { ApiErrorBanner } from "../ui/ApiErrorBanner.js"; @@ -162,6 +164,9 @@ export function OrderDetailScreen({ const [forceDelete, setForceDelete] = useState<boolean>(false); const [isDeleting, setIsDeleting] = useState<boolean>(false); const [deleteError, setDeleteError] = useState<string>(""); + // Open the confirmation on its safe choice. The dialog only hears Escape + // while focus is inside it, and the menu that opens it leaves focus behind. + const deleteCancel = useRef<HTMLButtonElement>(null); const [now, setNow] = useState<AbsoluteTimeValue>( nowProp ?? AbsoluteTime.now(), @@ -376,15 +381,15 @@ export function OrderDetailScreen({ <div class="space-y-6"> {/* Delete Confirmation Modal */} {showDeleteModal && ( - // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions -- a dialog closing on Escape is the pattern the rule exists to ask for; it just does not count `dialog` as interactive. - <div - role="dialog" - aria-modal="true" - tabIndex={-1} - onKeyDown={(e) => { - if (e.key === "Escape") setShowDeleteModal(false); + <Modal + isOpen + bare + onClose={() => { + if (!isDeleting) setShowDeleteModal(false); }} - class="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-xs" + initialFocus={() => deleteCancel.current} + ariaLabel={t`Delete Order`} + overlayClass="fixed inset-0 z-50 flex items-center justify-center p-4 bg-black/50 backdrop-blur-xs" > <div class="bg-white rounded-xl shadow-2xl p-6 max-w-sm w-full space-y-4"> <h3 class="text-lg font-bold text-gray-900">{t`Delete Order`}</h3> @@ -408,6 +413,7 @@ export function OrderDetailScreen({ </label> <div class="flex space-x-3 pt-2"> <button + ref={deleteCancel} onClick={() => setShowDeleteModal(false)} class="flex-1 px-4 py-2 text-xs font-bold bg-gray-100 rounded-lg hover:bg-gray-200 cursor-pointer" >{t`Cancel`}</button> @@ -420,7 +426,7 @@ export function OrderDetailScreen({ </button> </div> </div> - </div> + </Modal> )} {/* Top Header & Primary Actions */} diff --git a/packages/taler-merchant-webui/src/screens/ReportsScreen.tsx b/packages/taler-merchant-webui/src/screens/ReportsScreen.tsx @@ -893,6 +893,7 @@ export function ReportsScreen({ id="grp_name_input" type="text" required + autofocus value={groupName} onInput={(e) => setGroupName((e.target as HTMLInputElement).value) @@ -974,6 +975,7 @@ export function ReportsScreen({ id="pot_name_input" type="text" required + autofocus value={potName} onInput={(e) => setPotName((e.target as HTMLInputElement).value) diff --git a/packages/taler-merchant-webui/src/screens/TemplatesScreen.tsx b/packages/taler-merchant-webui/src/screens/TemplatesScreen.tsx @@ -14,8 +14,10 @@ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> */ +import { Modal } from "../ui/Modal.js"; + import type { VNode } from "preact"; -import { useState, useEffect } from "preact/hooks"; +import { useState, useEffect, useRef } from "preact/hooks"; import { useLocation } from "wouter-preact"; import { Header } from "../ui/Header.js"; import { TalerQrCode } from "../ui/TalerQrCode.js"; @@ -104,6 +106,12 @@ export function TemplatesScreen({ } }; + // These dialogs are opened from a row's action menu, which hands focus back + // to its trigger behind the overlay. Move it into the dialog instead, onto + // the choice that changes nothing. + const deleteCancel = useRef<HTMLButtonElement>(null); + const qrClose = useRef<HTMLButtonElement>(null); + useEffect(() => { if (!previewQrTemplate && !viewingTemplate && !deletingTemplate) return; const handleKeyDown = (e: KeyboardEvent) => { @@ -282,19 +290,14 @@ export function TemplatesScreen({ </div> )} {deletingTemplate && ( - // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions -- a native <dialog> already closes on Escape through onCancel; the click handler only adds backdrop dismissal. - <dialog - open - class="fixed inset-0 bg-black/40 flex items-center justify-center p-4 z-50 max-w-none w-full h-full border-0 bg-transparent m-0 backdrop:bg-black/40 cursor-pointer" - onCancel={(e) => { - e.preventDefault(); - setDeletingTemplate(null); - }} - onClick={(e) => { - if (e.target === e.currentTarget) { - setDeletingTemplate(null); - } - }} + <Modal + isOpen + bare + dismissOnBackdrop + onClose={() => setDeletingTemplate(null)} + initialFocus={() => deleteCancel.current} + ariaLabel={t`Delete Template?`} + overlayClass="fixed inset-0 bg-black/40 flex items-center justify-center p-4 z-50 max-w-none w-full h-full border-0 bg-transparent m-0 backdrop:bg-black/40 cursor-pointer" > <div class="bg-white rounded-xl max-w-md w-full p-6 shadow-xl space-y-4 cursor-default text-left"> <h3 class="text-base font-bold text-gray-900">{t`Delete Template?`}</h3> @@ -303,6 +306,7 @@ export function TemplatesScreen({ </p> <div class="flex items-center justify-end space-x-3 pt-2"> <button + ref={deleteCancel} type="button" onClick={() => setDeletingTemplate(null)} disabled={isDeleting} @@ -325,24 +329,19 @@ export function TemplatesScreen({ title={t`The template could not be deleted`} /> </div> - </dialog> + </Modal> )} {/* Show QR Code Modal */} {previewQrTemplate && ( - // eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-noninteractive-element-interactions -- a native <dialog> already closes on Escape through onCancel; the click handler only adds backdrop dismissal. - <dialog - open - class="fixed inset-0 bg-black/40 flex items-center justify-center p-4 z-50 max-w-none w-full h-full border-0 bg-transparent m-0 backdrop:bg-black/40 cursor-pointer" - onCancel={(e) => { - e.preventDefault(); - setPreviewQrTemplate(null); - }} - onClick={(e) => { - if (e.target === e.currentTarget) { - setPreviewQrTemplate(null); - } - }} + <Modal + isOpen + bare + dismissOnBackdrop + onClose={() => setPreviewQrTemplate(null)} + initialFocus={() => qrClose.current} + ariaLabel={previewQrTemplate.name} + overlayClass="fixed inset-0 bg-black/40 flex items-center justify-center p-4 z-50 max-w-none w-full h-full border-0 bg-transparent m-0 backdrop:bg-black/40 cursor-pointer" > <div data-print-sheet @@ -391,6 +390,7 @@ export function TemplatesScreen({ {t`🖨 Print Sheet`} </button> <button + ref={qrClose} type="button" onClick={() => setPreviewQrTemplate(null)} class="px-5 py-2 text-xs font-semibold rounded-md bg-gray-200 hover:bg-gray-300 text-gray-800 transition-colors cursor-pointer" @@ -399,7 +399,7 @@ export function TemplatesScreen({ </button> </div> </div> - </dialog> + </Modal> )} </div> );