View Issue Details

IDProjectCategoryView StatusLast Update
0012059Talerotherpublic2026-11-18 17:07
Reporterbot-cg [agent]  
CommunicatorCM_7  
PrioritynormalSeveritytrivial 
Status closedResolutionfixed 
Target Version1.6Fixed in Version1.6 
Summary0012059: web-util: Date fields: the calendar dialog opens with focus left behind the overlay, and closing it drops focus to the page body
DescriptionWhat happens:
absoluteTimeText/isoDateText fields (VQF 902.x KYC forms, AML decision Information 'Expiration', AML Rules) open a modal Calendar inside Dialog when the calendar button is clicked. Focus stays on the calendar button underneath the grey overlay; keyboard users have to Tab through the backdrop and the year/month arrows to reach a day. After a day is picked, the dialog unmounts and focus falls to BODY, so Tab restarts at the top of the page. Escape does nothing.

Expected:
Opening the picker focuses the selected day (Enter keeps it, Tab walks the month); picking a day or pressing Escape closes the picker and returns focus to the calendar button.

Where:
  - packages/web-util/src/forms/Calendar.tsx:53
  - packages/web-util/src/forms/Dialog.tsx:13

Measured in headless Chromium (document.activeElement):
  before: open: calendar trigger BUTTON behind the overlay; after picking a day: BODY; Escape: no effect
  after: open: day BUTTON '11' (selected day); after 'Next month' click: stays on 'Next month'; after picking a day: calendar trigger BUTTON; after Escape: calendar trigger BUTTON

Proposed fix:
Calendar focuses its selected day on mount (useAutoFocus, so navigating months does not pull focus back). Dialog remembers the focused element when it opens and restores it when it closes, and closes on Escape (onClose read through a ref, because callers pass an inline arrow). Needs the useAutoFocus helper from web-util--form-focus.diff.

Patch against taler-typescript-core master attached; the same change is committed on branch dev/bots/autofocus (durian). Screenshots attached (focused element outlined in red): 'before' is master, 'after' is with the patch.

Verified: tsc ok (no new errors); eslint clean; no unit tests exist for Calendar/Dialog; Chromium calendar scenario before/after
TagsNo tags attached.
Attached Files
web-util--date-picker-dialog.diff (3,032 bytes)   
diff --git a/packages/web-util/src/forms/Calendar.tsx b/packages/web-util/src/forms/Calendar.tsx
index e25f17e13..3a24ff61d 100644
--- a/packages/web-util/src/forms/Calendar.tsx
+++ b/packages/web-util/src/forms/Calendar.tsx
@@ -19,7 +19,7 @@ import {
 import { VNode, h } from "preact";
 import { useEffect, useRef, useState } from "preact/hooks";
 import { useTranslationContext } from "../context/translation.js";
-import { composeRef, saveRef } from "../components/utils.js";
+import { composeRef, saveRef, useAutoFocus } from "../components/utils.js";
 
 const THIS_MONTH = getMonth(new Date());
 const THIS_YEAR = getYear(new Date());
@@ -47,6 +47,12 @@ export function Calendar({
     if (input.current === document.activeElement) return;
     input.current.value = !year ? "" : String(year);
   }, [year]);
+  // The calendar is a picker the user has just opened: start on the selected
+  // day so that Enter keeps it and Tab moves on through the month.
+  const days = useRef<HTMLDivElement>(null);
+  useAutoFocus(true, () =>
+    days.current?.querySelector<HTMLElement>('[data-selected="true"]'),
+  );
 
   const start = startOfWeek(startOfMonth(showingDate), { weekStartsOn: 1 });
   const end = endOfWeek(endOfMonth(showingDate), { weekStartsOn: 1 });
@@ -183,7 +189,10 @@ export function Calendar({
         ))}
       </div>
       <div class="isolate mt-2">
-        <div class="grid grid-cols-7 gap-px rounded-lg bg-gray-200 text-sm shadow ring-1 ring-gray-200">
+        <div
+          ref={days}
+          class="grid grid-cols-7 gap-px rounded-lg bg-gray-200 text-sm shadow ring-1 ring-gray-200"
+        >
           {daysInMonth.map((current, idx) => (
             <button
               type="button"
diff --git a/packages/web-util/src/forms/Dialog.tsx b/packages/web-util/src/forms/Dialog.tsx
index 4bf96a446..ddba23f14 100644
--- a/packages/web-util/src/forms/Dialog.tsx
+++ b/packages/web-util/src/forms/Dialog.tsx
@@ -1,4 +1,5 @@
 import { ComponentChildren, VNode, h } from "preact";
+import { useEffect, useRef } from "preact/hooks";
 import { useTranslationContext } from "../context/translation.js";
 
 export function Dialog({
@@ -9,6 +10,24 @@ export function Dialog({
   children: ComponentChildren;
 }): VNode {
   const { i18n } = useTranslationContext();
+  const onCloseRef = useRef(onClose);
+  onCloseRef.current = onClose;
+  useEffect(() => {
+    // Hand focus back to the control that opened the dialog, otherwise it is
+    // lost to the page body when the dialog content goes away.
+    const previousFocus =
+      document.activeElement instanceof HTMLElement
+        ? document.activeElement
+        : null;
+    function closeOnEscape(event: KeyboardEvent): void {
+      if (event.key === "Escape") onCloseRef.current?.();
+    }
+    document.addEventListener("keydown", closeOnEscape);
+    return () => {
+      document.removeEventListener("keydown", closeOnEscape);
+      previousFocus?.focus();
+    };
+  }, []);
   return (
     <div
       class="relative z-10"
web-util--calendar--before.png (26,044 bytes)   
web-util--calendar--before.png (26,044 bytes)   
web-util--calendar--after.png (25,828 bytes)   
web-util--calendar--after.png (25,828 bytes)   

Required notifications

Address or linkRemarkAdded byNotifiedActions

Relationships

child of 0012024 closed Web UIs (bank, wallet, exchange AML/KYC, challenger, auditor, web-util forms): dialogs and single-purpose forms open without keyboard focus on the obvious field 

Activities

bot-codex-florian-dold

2026-11-13 09:14

manager   ~0030506

commit be277f9e6cb0db916464e05020eb757b74ea3e23
Author: Florian Dold <dold@taler.net>
Date: Fri Nov 13 01:06:16 2026 +0100

    web-util: manage focus in the calendar, terms and settings dialogs
    
    Use dialog focus handling for entry, Escape and opener restoration.
    Start the calendar on the selected day and the terms reader on Close.
    
    Issue: https://bugs.taler.net/n/12058
    Issue: https://bugs.taler.net/n/12059
    Issue: https://bugs.taler.net/n/12060
    Assisted-by: LLM

commit 0db14837db18a79a4bee3ca81c0137bc20c01f92
Author: Florian Dold <dold@taler.net>
Date: Fri Nov 13 01:06:14 2026 +0100

    web-util: restore dialog openers and coordinate nested dialogs
    
    DialogFocusScope adds Escape handling and opener restoration to a focus
    scope. Hooks provide the same behavior for existing wrappers. Menus
    restore focus without trapping it; native dialogs retain browser Tab
    handling.
    
    After an initial request succeeds, discard the other eligible requests,
    including ones tried earlier while their controls were unavailable. Keep
    requests blocked by a modal and requests waiting after fallback focus.
    
    Issue: https://bugs.taler.net/n/12002
    Issue: https://bugs.taler.net/n/12024
    Issue: https://bugs.taler.net/n/12034
    Assisted-by: LLM

Issue History

Date ModifiedUsernameFieldChange
2026-11-10 23:42bot-cgNew Issue
2026-11-10 23:42bot-cgRelationship addedchild of 0012024
2026-11-10 23:43bot-cgFile Added: web-util--date-picker-dialog.diff
2026-11-10 23:43bot-cgFile Added: web-util--calendar--before.png
2026-11-10 23:43bot-cgFile Added: web-util--calendar--after.png
2026-11-11 16:28Christian GrothoffSeverityminor => trivial
2026-11-13 09:14bot-codex-florian-doldNote Added: 0030506
2026-11-13 09:14bot-codex-florian-doldStatusnew => closed
2026-11-13 09:14bot-codex-florian-doldResolutionopen => fixed
2026-11-18 17:02Christian GrothoffTarget Version => 1.6
2026-11-18 17:07Christian GrothoffFixed in Version => 1.6