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(null); + useAutoFocus(true, () => + days.current?.querySelector('[data-selected="true"]'), + ); const start = startOfWeek(startOfMonth(showingDate), { weekStartsOn: 1 }); const end = endOfWeek(endOfMonth(showingDate), { weekStartsOn: 1 }); @@ -183,7 +189,10 @@ export function Calendar({ ))}
-
+
{daysInMonth.map((current, idx) => (