Kommentare beschreiben den heutigen Stand und warum er so ist, nicht mehr die Entwicklungsgeschichte: keine Datumsangaben zu Ereignissen, keine Vorfaelle an Testpersonen, keine Lieferantensicht, keine internen Namen oder Plattformen. In Migrationen nur Kommentare ausserhalb von Dollar-Quoting; Kommentare in Funktionskoerpern nur dort, wo ihr Text in keiner anderen Migration als Anker vorkommt. - Andreis Anpassungen aus windows-uebergabe nach master uebernommen. - LOLYO-Startpasswort kommt aus LOLYO_STARTPASSWORT statt aus dem Code; ohne Wert lehnt der Export mit Hinweis ab. - Beispiel- und erzeugte E-Mail-Adressen ohne Kundendomain. - Content-Security-Policy wird durchgesetzt; form-action fest mit login.microsoftonline.com, weil das Paket ohne Umgebungswerte gebaut wird. Geprueft im Browser: alle Seiten ohne Verstoss, Weiterleitung zu Microsoft geht durch. - migrate.mjs: einmalige Uebernahme der alten Buchfuehrung entfernt (seit 20260907100000 ohne Wirkung). - freischalten.ps1 vergibt und entzieht den HR-Zugang (-Entziehen) und protokolliert beides im Audit-Log. - docs/security-review.md -> docs/sicherheitskonzept.md: beschreibt den heutigen Stand ohne offene Punkte. README, entra-sso.md und deploy/windows/README.md ohne Widersprueche (Leserolle der IT, Freischaltung, Konto des Nachtlaufs), Abnahme-Checkliste statt "noch offen". Geprueft: lint, tsc, types:check, 823 Unit-Tests, Waechter (412 Dateien, keine Funde), alle 114 Migrationen auf leerem PostgreSQL 18 (zweiter Lauf leer), rauchtest.sql und vertragsangaben.sql bestanden.
91 lines
3.3 KiB
TypeScript
91 lines
3.3 KiB
TypeScript
"use client";
|
|
|
|
import { useEffect, useRef, type RefObject } from "react";
|
|
|
|
// Everything a dialog owes the keyboard, in one place so Modal and SlideOver
|
|
// cannot drift apart: focus moves into the dialog, Tab stays inside it,
|
|
// Escape closes it, and closing returns focus to whatever opened it —
|
|
// otherwise focus would land on <body> and the next Tab would start again
|
|
// from the top of the document.
|
|
const FOCUSABLE = [
|
|
"a[href]",
|
|
"button:not([disabled])",
|
|
"input:not([disabled]):not([type='hidden'])",
|
|
"select:not([disabled])",
|
|
"textarea:not([disabled])",
|
|
"[tabindex]:not([tabindex='-1'])",
|
|
].join(",");
|
|
|
|
function focusableWithin(container: HTMLElement): HTMLElement[] {
|
|
return [...container.querySelectorAll<HTMLElement>(FOCUSABLE)].filter(
|
|
(el) => el.offsetParent !== null || el.getClientRects().length > 0
|
|
);
|
|
}
|
|
|
|
export function useDialogFocus(open: boolean, onClose: () => void, containerRef: RefObject<HTMLElement | null>) {
|
|
const restoreToRef = useRef<HTMLElement | null>(null);
|
|
|
|
// onClose wird von den meisten Aufrufern bei jedem Rendern neu erzeugt.
|
|
// Stünde es in den Abhängigkeiten, liefe dieser Effekt nach jedem Rendern
|
|
// erneut — und sein Aufräumen holt den Fokus dorthin zurück, wo er vor dem
|
|
// Öffnen war. In einem Dialog mit Eingabefeldern hiesse das: nach dem
|
|
// ersten Zeichen springt der Fokus auf den Knopf, der ihn geöffnet hat, und
|
|
// der Rest der Eingabe geht ins Leere. Über eine Referenz bleibt der
|
|
// aktuelle Rückruf erreichbar, ohne dass der Effekt daran hängt.
|
|
const schliessen = useRef(onClose);
|
|
useEffect(() => {
|
|
schliessen.current = onClose;
|
|
});
|
|
|
|
useEffect(() => {
|
|
if (!open) return;
|
|
const container = containerRef.current;
|
|
restoreToRef.current = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
|
|
|
// First field rather than the close button: the point of opening these is
|
|
// to fill them in. autoFocus on a child wins, since it has already run.
|
|
if (container && !container.contains(document.activeElement)) {
|
|
const [first] = focusableWithin(container);
|
|
(first ?? container).focus();
|
|
}
|
|
|
|
function onKeyDown(e: KeyboardEvent) {
|
|
if (e.key === "Escape") {
|
|
schliessen.current();
|
|
return;
|
|
}
|
|
if (e.key !== "Tab" || !container) return;
|
|
|
|
const focusable = focusableWithin(container);
|
|
if (focusable.length === 0) {
|
|
e.preventDefault();
|
|
return;
|
|
}
|
|
const first = focusable[0];
|
|
const last = focusable[focusable.length - 1];
|
|
const active = document.activeElement;
|
|
|
|
// Wrap around at both ends, and pull focus back in if it somehow
|
|
// escaped (a click on the backdrop, say).
|
|
if (!container.contains(active)) {
|
|
e.preventDefault();
|
|
(e.shiftKey ? last : first).focus();
|
|
} else if (e.shiftKey && active === first) {
|
|
e.preventDefault();
|
|
last.focus();
|
|
} else if (!e.shiftKey && active === last) {
|
|
e.preventDefault();
|
|
first.focus();
|
|
}
|
|
}
|
|
|
|
window.addEventListener("keydown", onKeyDown);
|
|
return () => {
|
|
window.removeEventListener("keydown", onKeyDown);
|
|
// Back to whatever opened the dialog, so the next Tab continues from
|
|
// there instead of restarting at the top of the page.
|
|
restoreToRef.current?.focus();
|
|
};
|
|
}, [open, containerRef]);
|
|
}
|