[249] Tastatur und Fokus in den neuen Dialogen und Leisten: gemeinsame Fokus-Hülle, Fokusring, aria, Hintergrund-Kürzel gesperrt
This commit is contained in:
24 files changed
+862
-103
No files matched your search
@@ -4128,6 +4128,13 @@ export const de = {
|
||||
"sheetGuides.remove": "Hilfslinie löschen",
|
||||
"sheetGuides.clear": "Alle löschen",
|
||||
"sheetGuides.close": "Schliessen",
|
||||
"sheetGuides.axis": "Richtung der Hilfslinie",
|
||||
"sheetGuides.position": "Position in mm",
|
||||
"sheetGuides.add": "Hilfslinie anlegen",
|
||||
"sheetGuides.rowPosition": "Hilfslinie {axis}, Position in mm",
|
||||
"sheetImage.x": "Bild X in mm",
|
||||
"sheetImage.y": "Bild Y in mm",
|
||||
"sheetImage.cropEdge": "Zuschnitt {edge} in Prozent",
|
||||
"sheetImage.cropStart": "Zuschneiden",
|
||||
"sheetImage.cropDone": "Fertig",
|
||||
"sheetImage.cropHint": "Kanten ziehen: das Bild bleibt stehen, der Ausschnitt ändert sich.",
|
||||
|
||||
@@ -4114,6 +4114,13 @@ export const en: Record<TranslationKey, string> = {
|
||||
"sheetGuides.remove": "Delete guide",
|
||||
"sheetGuides.clear": "Delete all",
|
||||
"sheetGuides.close": "Close",
|
||||
"sheetGuides.axis": "Guide direction",
|
||||
"sheetGuides.position": "Position in mm",
|
||||
"sheetGuides.add": "Add guide",
|
||||
"sheetGuides.rowPosition": "Guide {axis}, position in mm",
|
||||
"sheetImage.x": "Image X in mm",
|
||||
"sheetImage.y": "Image Y in mm",
|
||||
"sheetImage.cropEdge": "Crop {edge} in percent",
|
||||
"sheetImage.cropStart": "Crop",
|
||||
"sheetImage.cropDone": "Done",
|
||||
"sheetImage.cropHint": "Drag the edges: the image stays put, only the visible part changes.",
|
||||
|
||||
@@ -32,13 +32,18 @@ export function infoGroupFrame(st: GroupState, id: InfoGroupId, children: ReactN
|
||||
type="button"
|
||||
className="objinfo-group-head"
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? `objinfo-group-${id}` : undefined}
|
||||
title={t("objinfo.group.toggle")}
|
||||
onClick={() => toggleInfoGroup(id)}
|
||||
>
|
||||
<span className="objinfo-group-chev" aria-hidden="true">{open ? "▾" : "▸"}</span>
|
||||
{t(INFO_GROUP_TITLE[id])}
|
||||
</button>
|
||||
{open && <div className="objinfo-group-body">{children}</div>}
|
||||
{open && (
|
||||
<div className="objinfo-group-body" id={`objinfo-group-${id}`}>
|
||||
{children}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -49,6 +49,7 @@ in `ProjectSync`.
|
||||
| `useMouseSelectionHandlers.ts` | Auswahl und Kontextmenü aus Grundriss und 3D |
|
||||
| `useKeyboardShortcuts.ts`, `keyboardShortcuts.ts`, `commandKeys.ts` | Tastenkürzel, Esc/Enter laufender Befehle |
|
||||
| `shortcutOverview.ts`, `shortcutOverviewHook.ts` | [210] Kürzel-Übersicht (Hilfe → Tastaturkürzel …): Liste aus `SHORTCUT_DEFS` und der Befehls-Registry abgeleitet, nichts von Hand gepflegt; Anzeige `ui/ShortcutOverviewDialog.tsx` |
|
||||
| `modalScope.ts` | [249] `isInModalDialog`: Ziele in `aria-modal`-Dialogen gehören dem Dialog, nicht den App-Kürzeln |
|
||||
| `sheetGuides.ts`, `layoutImageActions.ts` | [208] Hilfslinien am Masterlayout und Aktionen für Bilder auf dem Blatt |
|
||||
| `objectSettings.ts` | Taste T / Menü „Objekteinstellungen…" ([195]): öffnet das schwebende Fenster `object-settings` und klappt den passenden Abschnitt der Objekt-Info auf; `mixedValues.ts`: gemeinsamer Wert über die Mehrfachauswahl (abweichend = leer) |
|
||||
| `useDisplayResolvers.ts` | sichtbar, gedimmt, gesperrt je Ebene und Kategorie |
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
// [249] Gehört das Ereignisziel zu einem offenen modalen Dialog (`aria-modal="true"`)? Dann dürfen die App-Kürzel
|
||||
// im Hintergrund (Entf, T, W/A/S/D, Auswahl-Esc …) nicht reagieren: die Taste gehört dem Dialog.
|
||||
|
||||
export function isInModalDialog(target: EventTarget | Element | null): boolean {
|
||||
const el = target as HTMLElement | null;
|
||||
return !!el && typeof el.closest === "function" && el.closest('[aria-modal="true"]') !== null;
|
||||
}
|
||||
@@ -34,13 +34,15 @@ import type { ElementClipboard, ElementSelectionIds, PastedIds } from "../editor
|
||||
import { parseClipboardText, serializeClipboardText } from "../editors/elementClipboardSerialize";
|
||||
import { matchesShortcut, type ShortcutId, type ShortcutOverrides } from "./keyboardShortcuts";
|
||||
import { isolateSelectionLayerCodes, showAllLayerCodes } from "./layerIsolate";
|
||||
import { isInModalDialog } from "./modalScope";
|
||||
import { toggleTraceAction } from "./traceActions";
|
||||
import { joinCurrentSelection } from "./selectionJoin";
|
||||
import { hideSelectionIn3d, showSelectionIn3d, stepActiveFloor } from "./tabNavigation";
|
||||
|
||||
const isEditableTarget = (e: KeyboardEvent): boolean => {
|
||||
const el = e.target as HTMLElement | null;
|
||||
return !!el && (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable);
|
||||
// [249] Auch ein Knopf/Text im modalen Dialog gehört dem Dialog, nicht den App-Kürzeln.
|
||||
return !!el && (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable || isInModalDialog(el));
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -123,6 +125,8 @@ export function useCommandTabShortcut(
|
||||
if (inInput) {
|
||||
return;
|
||||
}
|
||||
// [249] In einer Werkzeugleiste (3D-Leiste) bleibt Tab die normale Tastaturnavigation zwischen ihren Knöpfen.
|
||||
if ((e.target as HTMLElement | null)?.closest?.('[role="toolbar"]')) return;
|
||||
e.preventDefault();
|
||||
const eng = engineRef.current;
|
||||
if (eng?.isActive() && eng.hasFields()) {
|
||||
@@ -196,6 +200,7 @@ export function useToolNumberShortcuts(
|
||||
if (gripDragInfoRef?.current) return;
|
||||
if (edgeDragInfoRef?.current) return;
|
||||
const el = e.target as HTMLElement | null;
|
||||
if (isInModalDialog(el)) return;
|
||||
const isInput =
|
||||
!!el && (el.tagName === "INPUT" || el.tagName === "TEXTAREA" || el.isContentEditable);
|
||||
if (isInput) {
|
||||
|
||||
@@ -9272,3 +9272,34 @@ body {
|
||||
font-size: 11px;
|
||||
font-style: italic;
|
||||
}
|
||||
|
||||
/* ── [249] Sichtbarer Fokusring in hell und dunkel ───────────────────────────────────────────────────────────
|
||||
Bisher zeigten Dialog-Knöpfe nur den Browser-Standard (im Dark-Modus kaum sichtbar), Eingabefelder meist nur eine
|
||||
20-%-Kontur und die Blatt-HUDs nichts. Ein Token, eine Regel für Dialoge, Blatt-HUDs, Objekt-Info-Gruppen und
|
||||
Dropdown-Trigger; nur Tastaturfokus (`:focus-visible`), Mausklicks bleiben ruhig. */
|
||||
:root {
|
||||
--focus-ring: #1f5fbf;
|
||||
}
|
||||
:root[data-theme="dark"] {
|
||||
--focus-ring: #8ab4ff;
|
||||
}
|
||||
.imp-dialog :is(button, input, select, textarea, summary, [tabindex]):focus-visible,
|
||||
.layout-sheet-hud :is(button, input, select, textarea, [tabindex]):focus-visible,
|
||||
.layout-sheet-bind :is(button, input, select, textarea):focus-visible,
|
||||
.objinfo-group-head:focus-visible,
|
||||
.tb-dd-trigger:focus-visible,
|
||||
.tb-btn:focus-visible,
|
||||
.nav-add:focus-visible {
|
||||
outline: 2px solid var(--focus-ring);
|
||||
outline-offset: 1px;
|
||||
}
|
||||
.imp-dialog:focus,
|
||||
.imp-dialog:focus-visible {
|
||||
outline: none;
|
||||
}
|
||||
/* [249] Viele Hilfslinien: die Liste scrollt im Panel, Titel und Schliessen-Knopf bleiben im Blatt sichtbar. */
|
||||
.layout-sheet-guides {
|
||||
max-height: calc(100% - 24px);
|
||||
overflow-y: auto;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
+13
-10
@@ -4,6 +4,7 @@
|
||||
// Esc oder Klick in den Viewport brechen ebenfalls ab). Zustand: `cameraTourDialogState.ts`; Öffner `state/cameraTourDialogHook`.
|
||||
|
||||
import { memo, useCallback, useEffect, useMemo, useReducer, useRef } from "react";
|
||||
import { useModalFocus } from "./modalFocus";
|
||||
import { t } from "../i18n";
|
||||
import { getState } from "../state/appStore";
|
||||
import { cancelCameraTour, currentTourKeys, getTourSettings, playCameraTour, recordCameraTour, setTourSettings } from "../state/cameraTourActions";
|
||||
@@ -37,14 +38,10 @@ export const CameraTourDialogHost = memo(function CameraTourDialogHost() {
|
||||
}, []);
|
||||
|
||||
const close = useCallback(() => dispatch({ type: "close" }), []);
|
||||
useEffect(() => {
|
||||
if (!s.open) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && s.phase !== "running") close();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [s.open, s.phase, close]);
|
||||
// [249] Fokus ins erste Feld (Dauer; nach der Aufnahme „Speichern"), Tab-Falle, Esc, Enter = Hauptaktion, Fokus zurück.
|
||||
// Esc während der Fahrt bricht die Fahrt ab (cameraTourPlayer); die Leiste ist kein modaler Dialog.
|
||||
const primaryRef = useRef<() => void>(() => {});
|
||||
const dialogRef = useModalFocus({ onEscape: close, onEnter: () => primaryRef.current() });
|
||||
|
||||
if (!s.open) return null;
|
||||
|
||||
@@ -91,6 +88,12 @@ export const CameraTourDialogHost = memo(function CameraTourDialogHost() {
|
||||
}
|
||||
};
|
||||
|
||||
primaryRef.current = () => {
|
||||
if (s.phase === "done") void save();
|
||||
else if (canRecord(s)) void record();
|
||||
else if (canStart(s)) void play();
|
||||
};
|
||||
|
||||
if (s.phase === "running") {
|
||||
return (
|
||||
<div
|
||||
@@ -115,7 +118,7 @@ export const CameraTourDialogHost = memo(function CameraTourDialogHost() {
|
||||
const res = resultRef.current;
|
||||
return (
|
||||
<div className="imp-overlay" data-tour-ui onClick={close}>
|
||||
<div className="imp-dialog render-dialog" role="dialog" aria-modal="true" aria-label={t("tour.title")} data-testid="tour-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div ref={dialogRef} className="imp-dialog render-dialog" role="dialog" aria-modal="true" aria-label={t("tour.title")} data-testid="tour-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<header className="imp-head">
|
||||
<span className="imp-head-title">{t("tour.title")}</span>
|
||||
<button className="imp-close" onClick={close} aria-label={t("export.close")}>
|
||||
@@ -197,7 +200,7 @@ export const CameraTourDialogHost = memo(function CameraTourDialogHost() {
|
||||
<button className="imp-btn" onClick={() => dispatch({ type: "again" })}>
|
||||
{t("tour.again")}
|
||||
</button>
|
||||
<button className="imp-btn primary" data-testid="tour-save" onClick={() => void save()}>
|
||||
<button className="imp-btn primary" data-testid="tour-save" data-autofocus onClick={() => void save()}>
|
||||
{t("tour.save")}
|
||||
</button>
|
||||
</>
|
||||
|
||||
@@ -31,6 +31,19 @@ describe("Dropdown [244]", () => {
|
||||
expect(h).toContain(">G1<");
|
||||
});
|
||||
|
||||
it("[249] Gruppen sind benannte role=group (Name = Überschrift), Optionen nicht per Tab erreichbar, Ids für activedescendant", () => {
|
||||
const rows = optionRows([
|
||||
{ value: "a", label: "A", group: "G1" }, { value: "b", label: "B", group: "G1" }, { value: "c", label: "C", group: "G2" },
|
||||
]);
|
||||
const h = renderToStaticMarkup(createElement(DropdownRows, { rows, activeIdx: 2, onHover: () => {}, onSelect: () => {}, idPrefix: "dd-x" }));
|
||||
expect(h.match(/role="group"/g)).toHaveLength(2);
|
||||
expect(h).toContain('aria-labelledby="dd-x-head-0"');
|
||||
expect(h).toContain('id="dd-x-head-0"');
|
||||
expect(h).toContain('id="dd-x-2"'); // Index in der flachen Zeilenliste (Überschrift 0, A 1, B 2 …)
|
||||
expect(h.match(/tabindex="-1"/g)).toHaveLength(3);
|
||||
expect(h).toContain("tb-dd-item is-active");
|
||||
});
|
||||
|
||||
it("Icon, Zweitzeile, Tooltip, Kürzel und Häkchen", () => {
|
||||
const h = html(optionRows([{ value: "a", label: "A", icon: "view_in_ar", hint: "Erklärung", shortcut: "W" }], "a"));
|
||||
expect(h).toContain("material-symbols-outlined tb-dd-icon");
|
||||
|
||||
+88
-39
@@ -16,7 +16,7 @@
|
||||
// Reine Darstellung + Callbacks; voll gesteuert. Identifier englisch, UI-Text
|
||||
// kommt als Props (i18n) herein (CONVENTIONS.md).
|
||||
|
||||
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
||||
import { useEffect, useId, useLayoutEffect, useRef, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
import type { ReactNode } from "react";
|
||||
|
||||
@@ -96,51 +96,74 @@ export function DropdownRows({
|
||||
activeIdx,
|
||||
onHover,
|
||||
onSelect,
|
||||
idPrefix,
|
||||
}: {
|
||||
rows: DropdownItem[];
|
||||
activeIdx: number;
|
||||
onHover: (i: number) => void;
|
||||
onSelect: (row: DropdownItem) => void;
|
||||
/** [249] Ids der Zeilen (`<prefix>-<Index>`) für `aria-activedescendant` des Triggers. */
|
||||
idPrefix?: string;
|
||||
}) {
|
||||
return (
|
||||
<>
|
||||
{rows.map((row, i) =>
|
||||
row.divider ? (
|
||||
<div key={`div-${i}`} className="ctx-divider" role="separator" />
|
||||
) : row.heading !== undefined ? (
|
||||
<div key={`head-${i}`} className="tb-dd-heading" role="presentation">
|
||||
const option = (row: DropdownItem, i: number) => (
|
||||
<button
|
||||
key={`row-${i}`}
|
||||
id={idPrefix ? `${idPrefix}-${i}` : undefined}
|
||||
type="button"
|
||||
role="option"
|
||||
tabIndex={-1}
|
||||
aria-selected={!!row.active}
|
||||
title={row.hint}
|
||||
className={`ctx-item tb-dd-item${row.danger ? " danger" : ""}${row.hint ? " has-hint" : ""}${i === activeIdx ? " is-active" : ""}`}
|
||||
disabled={row.disabled}
|
||||
onMouseEnter={() => !row.disabled && onHover(i)}
|
||||
onClick={() => onSelect(row)}
|
||||
>
|
||||
<span className="tb-dd-check-slot">{row.active && <Check />}</span>
|
||||
{row.icon && (
|
||||
<span className="material-symbols-outlined tb-dd-icon" aria-hidden="true">
|
||||
{row.icon}
|
||||
</span>
|
||||
)}
|
||||
<span className="tb-dd-text">
|
||||
<span className="ctx-item-label">{row.label}</span>
|
||||
{row.hint && <span className="tb-dd-hint">{row.hint}</span>}
|
||||
</span>
|
||||
{row.shortcut && <kbd className="tb-dd-kbd">{row.shortcut}</kbd>}
|
||||
</button>
|
||||
);
|
||||
// [249] Überschrift + folgende Optionen = eine benannte Gruppe (`role="group"`, Name = Überschrift), damit
|
||||
// Screenreader „Linien, Drahtgitter …" ansagen; Trenner stehen zwischen den Gruppen.
|
||||
const out: ReactNode[] = [];
|
||||
let i = 0;
|
||||
while (i < rows.length) {
|
||||
const row = rows[i]!;
|
||||
if (row.divider) {
|
||||
out.push(<div key={`div-${i}`} className="ctx-divider" role="separator" />);
|
||||
i++;
|
||||
} else if (row.heading !== undefined) {
|
||||
const headId = `${idPrefix ?? "dd"}-head-${i}`;
|
||||
const members: ReactNode[] = [];
|
||||
let k = i + 1;
|
||||
while (k < rows.length && !isInert(rows[k]!)) {
|
||||
members.push(option(rows[k]!, k));
|
||||
k++;
|
||||
}
|
||||
out.push(
|
||||
<div key={`grp-${i}`} role="group" aria-labelledby={headId}>
|
||||
<div id={headId} className="tb-dd-heading">
|
||||
{row.heading}
|
||||
</div>
|
||||
) : (
|
||||
<button
|
||||
key={`row-${i}`}
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected={!!row.active}
|
||||
title={row.hint}
|
||||
className={`ctx-item tb-dd-item${row.danger ? " danger" : ""}${row.hint ? " has-hint" : ""}${
|
||||
i === activeIdx ? " is-active" : ""
|
||||
}`}
|
||||
disabled={row.disabled}
|
||||
onMouseEnter={() => !row.disabled && onHover(i)}
|
||||
onClick={() => onSelect(row)}
|
||||
>
|
||||
<span className="tb-dd-check-slot">{row.active && <Check />}</span>
|
||||
{row.icon && (
|
||||
<span className="material-symbols-outlined tb-dd-icon" aria-hidden="true">
|
||||
{row.icon}
|
||||
</span>
|
||||
)}
|
||||
<span className="tb-dd-text">
|
||||
<span className="ctx-item-label">{row.label}</span>
|
||||
{row.hint && <span className="tb-dd-hint">{row.hint}</span>}
|
||||
</span>
|
||||
{row.shortcut && <kbd className="tb-dd-kbd">{row.shortcut}</kbd>}
|
||||
</button>
|
||||
),
|
||||
)}
|
||||
</>
|
||||
);
|
||||
{members}
|
||||
</div>,
|
||||
);
|
||||
i = k;
|
||||
} else {
|
||||
out.push(option(row, i));
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return <>{out}</>;
|
||||
}
|
||||
|
||||
export interface DropdownProps {
|
||||
@@ -238,6 +261,9 @@ export function Dropdown({
|
||||
const [activeIdx, setActiveIdx] = useState(-1);
|
||||
const btnRef = useRef<HTMLButtonElement | null>(null);
|
||||
const menuRef = useRef<HTMLDivElement | null>(null);
|
||||
// [249] Ids für aria-controls/aria-activedescendant (der Fokus bleibt auf dem Trigger).
|
||||
const uid = useId().replace(/:/g, "");
|
||||
const menuId = `dd-${uid}`;
|
||||
|
||||
// Einheitliche Zeilenliste: im Wert-Modus aus `options`, im Aktions-Modus aus
|
||||
// `items`. So teilen beide Modi dieselbe Render-/Tastatur-Logik.
|
||||
@@ -272,6 +298,9 @@ export function Dropdown({
|
||||
|
||||
const selectRow = (row: DropdownItem) => {
|
||||
if (row.disabled || isInert(row)) return;
|
||||
// [249] Fokus zuerst zum Trigger (nach einem Mausklick liegt er sonst auf der Zeile, die gleich verschwindet):
|
||||
// ein von der Aktion geöffneter Dialog merkt sich ihn als Rückkehrziel.
|
||||
btnRef.current?.focus({ preventScroll: true });
|
||||
row.onSelect?.();
|
||||
close();
|
||||
};
|
||||
@@ -314,10 +343,20 @@ export function Dropdown({
|
||||
close();
|
||||
};
|
||||
const onScrollOrResize = () => close();
|
||||
// [249] Esc auch, wenn der Fokus nicht (mehr) auf dem Trigger liegt; Tab verlässt das Menü.
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && !e.defaultPrevented) {
|
||||
e.preventDefault();
|
||||
close();
|
||||
btnRef.current?.focus({ preventScroll: true });
|
||||
} else if (e.key === "Tab") close();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
window.addEventListener("pointerdown", onPointerDown, true);
|
||||
window.addEventListener("scroll", onScrollOrResize, true);
|
||||
window.addEventListener("resize", onScrollOrResize);
|
||||
return () => {
|
||||
window.removeEventListener("keydown", onKey);
|
||||
window.removeEventListener("pointerdown", onPointerDown, true);
|
||||
window.removeEventListener("scroll", onScrollOrResize, true);
|
||||
window.removeEventListener("resize", onScrollOrResize);
|
||||
@@ -349,6 +388,7 @@ export function Dropdown({
|
||||
}
|
||||
if (e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
close();
|
||||
} else if (e.key === "ArrowDown") {
|
||||
e.preventDefault();
|
||||
@@ -356,6 +396,11 @@ export function Dropdown({
|
||||
} else if (e.key === "ArrowUp") {
|
||||
e.preventDefault();
|
||||
step(-1);
|
||||
} else if (e.key === "Home" || e.key === "End") {
|
||||
e.preventDefault();
|
||||
const order = e.key === "Home" ? rows.map((_, i) => i) : rows.map((_, i) => rows.length - 1 - i);
|
||||
const to = order.find((i) => !isInert(rows[i]!) && !rows[i]!.disabled);
|
||||
if (to !== undefined) setActiveIdx(to);
|
||||
} else if (e.key === "Enter" || e.key === " ") {
|
||||
e.preventDefault();
|
||||
const row = rows[activeIdx];
|
||||
@@ -366,12 +411,14 @@ export function Dropdown({
|
||||
const menu = open ? (
|
||||
<div
|
||||
ref={menuRef}
|
||||
id={menuId}
|
||||
className="ctx-menu tb-dd-menu"
|
||||
role="listbox"
|
||||
aria-label={title ?? triggerLabel}
|
||||
style={{ left: pos.left, top: pos.top, minWidth: pos.minWidth }}
|
||||
onContextMenu={(e) => e.preventDefault()}
|
||||
>
|
||||
<DropdownRows rows={rows} activeIdx={activeIdx} onHover={setActiveIdx} onSelect={selectRow} />
|
||||
<DropdownRows rows={rows} activeIdx={activeIdx} onHover={setActiveIdx} onSelect={selectRow} idPrefix={menuId} />
|
||||
</div>
|
||||
) : null;
|
||||
|
||||
@@ -389,6 +436,8 @@ export function Dropdown({
|
||||
aria-label={title}
|
||||
aria-haspopup="listbox"
|
||||
aria-expanded={open}
|
||||
aria-controls={open ? menuId : undefined}
|
||||
aria-activedescendant={open && activeIdx >= 0 ? `${menuId}-${activeIdx}` : undefined}
|
||||
onClick={() => (open ? close() : openMenu())}
|
||||
onKeyDown={onTriggerKeyDown}
|
||||
>
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
// (`state/imageExportDialogHook`); Befehl `bild3d`, Menü Ansicht. Overlay wie `RenderDialog` (kein window.prompt).
|
||||
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { useModalFocus } from "./modalFocus";
|
||||
import { t } from "../i18n";
|
||||
import { paperPixels } from "../core";
|
||||
import { getState } from "../state/appStore";
|
||||
@@ -86,14 +87,13 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
|
||||
setResult(null);
|
||||
}, []);
|
||||
|
||||
// [249] Fokus ins erste Feld, Tab-Falle, Esc (nicht während der Arbeit), Enter im Feld = Starten, Fokus zurück.
|
||||
const startRef = useRef<() => void>(() => {});
|
||||
const dialogRef = useModalFocus({ onEscape: busy ? undefined : close, onEnter: () => startRef.current() });
|
||||
// Während der Arbeit ist „Starten" gesperrt: der Fokus wandert auf „Abbrechen" (nur im Stil Pathtracing vorhanden).
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && !busy) close();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [open, busy, close]);
|
||||
if (busy) document.querySelector<HTMLElement>('[data-testid="image3d-abort"]')?.focus();
|
||||
}, [busy]);
|
||||
|
||||
const cameras = useMemo(() => (open ? (getState().project.cameras ?? []) : []), [open]);
|
||||
if (!open) return null;
|
||||
@@ -107,6 +107,9 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
|
||||
const canStart = validDims && !busy;
|
||||
const layouts = getState().project.layouts ?? [];
|
||||
|
||||
startRef.current = () => {
|
||||
if (phase !== "done") void start();
|
||||
};
|
||||
const start = async () => {
|
||||
if (!canStart) return;
|
||||
const st = getState();
|
||||
@@ -167,7 +170,7 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
|
||||
|
||||
return (
|
||||
<div className="imp-overlay" onClick={() => !busy && close()}>
|
||||
<div className="imp-dialog render-dialog" role="dialog" aria-modal="true" aria-label={t("image3d.title")} data-testid="image3d-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<div ref={dialogRef} className="imp-dialog render-dialog" role="dialog" aria-modal="true" aria-label={t("image3d.title")} data-testid="image3d-dialog" onClick={(e) => e.stopPropagation()}>
|
||||
<header className="imp-head">
|
||||
<span className="imp-head-title">{t("image3d.title")}</span>
|
||||
<button className="imp-close" onClick={close} aria-label={t("export.close")} disabled={busy}>
|
||||
@@ -180,7 +183,7 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
|
||||
<p className="imp-note">{t("image3d.intro")}</p>
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("render.camera.title")}</div>
|
||||
<select className="imp-select" data-testid="image3d-camera" value={cameraKey} disabled={busy} onChange={(e) => setCameraKey(e.target.value)}>
|
||||
<select className="imp-select" aria-label={t("render.camera.title")} data-testid="image3d-camera" value={cameraKey} disabled={busy} onChange={(e) => setCameraKey(e.target.value)}>
|
||||
<option value="live">{t("render.camera.live")}</option>
|
||||
{cameras.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
@@ -191,7 +194,7 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
|
||||
</section>
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("render.size")}</div>
|
||||
<select className="imp-select" data-testid="image3d-size" value={size} disabled={busy} onChange={(e) => pickSize(e.target.value as SizeId)}>
|
||||
<select className="imp-select" aria-label={t("render.size")} data-testid="image3d-size" value={size} disabled={busy} onChange={(e) => pickSize(e.target.value as SizeId)}>
|
||||
{SIZE_IDS.map((id) => (
|
||||
<option key={id} value={id}>
|
||||
{t(`image3d.size.${id}`)}
|
||||
@@ -299,7 +302,7 @@ export const ImageExportDialogHost = memo(function ImageExportDialogHost() {
|
||||
>
|
||||
{t("render.toLayout")}
|
||||
</button>
|
||||
<button className="imp-btn primary" data-testid="image3d-save" onClick={() => void save()}>
|
||||
<button className="imp-btn primary" data-testid="image3d-save" data-autofocus onClick={() => void save()}>
|
||||
{t("render.save")}
|
||||
</button>
|
||||
</>
|
||||
|
||||
@@ -30,6 +30,7 @@ import type {
|
||||
import { createTable, PX_PER_M, sheetTables, TABLE_SOURCES, snapshotMono, snapshotOverrideRuleIds, snapshotTemplate, tableSourceLabel, viewportLevelPlan } from "../core";
|
||||
import type { TableOut } from "../core";
|
||||
import { SheetTableHud } from "./SheetTableHud";
|
||||
import { isInModalDialog } from "../state/modalScope";
|
||||
import { SheetImageHud } from "./SheetImageHud";
|
||||
import { SheetGuidesHud } from "./SheetGuidesHud";
|
||||
import {
|
||||
@@ -346,6 +347,7 @@ export function LayoutSheetPane({
|
||||
const [cropPreview, setCropPreview] = useState<{ id: string; clip: RectMm; draw: RectMm } | null>(null);
|
||||
// Hilfslinien ([208]): Panel offen, laufender Zug (Lineal / bestehende Linie) und gerade gefangene Linien.
|
||||
const [guidesOpen, setGuidesOpen] = useState(false);
|
||||
const guidesToggleRef = useRef<HTMLButtonElement | null>(null);
|
||||
const [guideDrag, setGuideDrag] = useState<{ index: number; axis: "x" | "y"; posMm: number } | null>(null);
|
||||
const [snapHits, setSnapHits] = useState<GuideHit[]>([]);
|
||||
// [137] Schriftfeld angeklickt → Felder bearbeiten.
|
||||
@@ -403,6 +405,7 @@ export function LayoutSheetPane({
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
const el = e.target as HTMLElement | null;
|
||||
if (el && (el.isContentEditable || /^(INPUT|TEXTAREA|SELECT)$/.test(el.tagName))) return;
|
||||
if (isInModalDialog(el)) return; // [249] Dialog über dem Blatt: Entf/Esc gehören ihm
|
||||
if (cropId && (e.key === "Escape" || e.key === "Enter")) {
|
||||
setCropId(null);
|
||||
} else if (e.key === "Escape") {
|
||||
@@ -1119,6 +1122,7 @@ export function LayoutSheetPane({
|
||||
}}
|
||||
/>
|
||||
<button
|
||||
ref={guidesToggleRef}
|
||||
className={`nav-add${guidesOpen ? " active" : ""}`}
|
||||
data-guides-toggle
|
||||
disabled={!canGuides}
|
||||
@@ -1162,7 +1166,11 @@ export function LayoutSheetPane({
|
||||
onMove={(i, posMm) => setGuidesNow(moveGuide(guides, i, posMm), `sheetGuide:${layout.id}:${i}`)}
|
||||
onRemove={(i) => setGuidesNow(removeGuide(guides, i))}
|
||||
onClear={() => setGuidesNow([])}
|
||||
onClose={() => setGuidesOpen(false)}
|
||||
onClose={() => {
|
||||
setGuidesOpen(false);
|
||||
// [249] Fokus zurück zum Knopf, der das Panel geöffnet hat.
|
||||
requestAnimationFrame(() => guidesToggleRef.current?.focus());
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ liegen in `src/panels`, Befehle in `src/commands`.
|
||||
|---|---|
|
||||
| `PromptDialog.tsx`, `UnsavedChangesDialog.tsx`, `RecoverAutosaveDialog.tsx`, `LockConflictDialog.tsx` | Ersatz für `window.prompt/confirm`: Eingabe, ungespeicherte Änderungen, Autosave, gesperrte Datei |
|
||||
| `ContextMenu.tsx`, `Dropdown.tsx`, `EditorField.tsx`, `EyeIcon.tsx` | Kontextmenü, Auswahlliste, beschriftetes Feld, Sichtbarkeits-Symbol |
|
||||
| `modalFocus.ts` | [249] `useModalFocus`: Fokus-Hülle der Overlay-Dialoge (Fokus beim Öffnen, Tab-Falle, Esc, Enter, Fokus zurück) |
|
||||
| `SettingsDialog.tsx`, `AiAccessSection.tsx`, `AiActivityPanel.tsx`, `LayoutMenu.tsx` | Einstellungen, KI-Zugriff und sein Protokoll (`[9]`), Arbeitsumgebungen |
|
||||
| `ColorMixer.tsx`, `SpectrumPicker.tsx`, `FreeColorPicker.tsx`, `ColorHexField.tsx`, `ColorSwatchCell.tsx`, `PenColorField.tsx`, `PenSwatchPicker.tsx` | Farbwahl: Mischer, Spektrum, freie Paletten, Stiftfarben |
|
||||
| `hatchPreview.tsx`, `MotifEditor.tsx` | Vorschau von Schraffuren und Linienstilen, Editor eines Wiederhol-Motivs |
|
||||
|
||||
+19
-13
@@ -6,6 +6,7 @@
|
||||
|
||||
import { memo, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
||||
import { t } from "../i18n";
|
||||
import { useModalFocus } from "./modalFocus";
|
||||
import {
|
||||
BLENDER_DOWNLOAD_URL,
|
||||
BlenderMissingError,
|
||||
@@ -113,14 +114,13 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
setPng(null);
|
||||
}, []);
|
||||
|
||||
// [249] Fokus ins erste Feld, Tab-Falle, Esc (nicht während der Arbeit), Enter im Feld = Starten, Fokus zurück.
|
||||
const startRef = useRef<() => void>(() => {});
|
||||
const dialogRef = useModalFocus({ onEscape: busy ? undefined : close, onEnter: () => startRef.current() });
|
||||
// Während der Arbeit ist „Starten" gesperrt: der Fokus wandert auf „Abbrechen".
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape" && !busy) close();
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [open, busy, close]);
|
||||
if (busy) document.querySelector<HTMLElement>('[data-testid="render-abort"]')?.focus();
|
||||
}, [busy]);
|
||||
|
||||
const date = useMemo(() => {
|
||||
const d = new Date(when);
|
||||
@@ -283,10 +283,15 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
|
||||
const camLabel = cameraKey !== "live" ? t("render.camera.saved", { name: cameras.find((c) => c.id === cameraKey)?.name ?? "" }) : "preset" in camera ? t("render.camera.preset", { name: t(`view3d.${camera.preset === "right" ? "side" : camera.preset}` as never) }) : t("render.camera.view");
|
||||
const browserOnly = host === null;
|
||||
startRef.current = () => {
|
||||
if (phase === "done" || phase === "missing" || host === undefined) return;
|
||||
if (browserOnly) void saveZip();
|
||||
else void start();
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="imp-overlay" onClick={() => !busy && close()}>
|
||||
<div className="imp-dialog render-dialog" role="dialog" aria-modal="true" aria-label={t("render.title")} onClick={(e) => e.stopPropagation()}>
|
||||
<div ref={dialogRef} className="imp-dialog render-dialog" role="dialog" aria-modal="true" aria-label={t("render.title")} onClick={(e) => e.stopPropagation()}>
|
||||
<header className="imp-head">
|
||||
<span className="imp-head-title">{t("render.title")}</span>
|
||||
<button className="imp-close" onClick={close} aria-label={t("export.close")} disabled={busy}>
|
||||
@@ -301,7 +306,7 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
{phase !== "done" && cameras.length > 0 && (
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("render.camera.title")}</div>
|
||||
<select className="imp-select" data-testid="render-camera-select" value={cameraKey} disabled={busy} onChange={(e) => pickCamera(e.target.value)}>
|
||||
<select className="imp-select" aria-label={t("render.camera.title")} data-testid="render-camera-select" value={cameraKey} disabled={busy} onChange={(e) => pickCamera(e.target.value)}>
|
||||
<option value="live">{t("render.camera.live")}</option>
|
||||
{cameras.map((c) => (
|
||||
<option key={c.id} value={c.id}>
|
||||
@@ -316,7 +321,7 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
<>
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("render.size")}</div>
|
||||
<select className="imp-select" data-testid="render-size" value={size} disabled={busy} onChange={(e) => pickSize(e.target.value as SizeId)}>
|
||||
<select className="imp-select" aria-label={t("render.size")} data-testid="render-size" value={size} disabled={busy} onChange={(e) => pickSize(e.target.value as SizeId)}>
|
||||
{(["hd", "uhd", "a4", "a3", "a2", "custom"] as SizeId[]).map((id) => (
|
||||
<option key={id} value={id}>
|
||||
{t(`render.size.${id}`)}
|
||||
@@ -336,7 +341,7 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
</section>
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("render.quality")}</div>
|
||||
<select className="imp-select" data-testid="render-quality" value={quality} disabled={busy} onChange={(e) => setQuality(e.target.value as typeof quality)}>
|
||||
<select className="imp-select" aria-label={t("render.quality")} data-testid="render-quality" value={quality} disabled={busy} onChange={(e) => setQuality(e.target.value as typeof quality)}>
|
||||
{RENDER_QUALITY_PRESETS.map((q) => (
|
||||
<option key={q.id} value={q.id}>
|
||||
{t(`render.quality.${q.id}`)}
|
||||
@@ -346,7 +351,7 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
</section>
|
||||
<section className="imp-section">
|
||||
<div className="imp-section-title">{t("render.time")}</div>
|
||||
<input className="imp-input imp-input-flush" type="datetime-local" data-testid="render-time" value={when} disabled={busy} onChange={(e) => setWhen(e.target.value)} />
|
||||
<input className="imp-input imp-input-flush" type="datetime-local" aria-label={t("render.time")} data-testid="render-time" value={when} disabled={busy} onChange={(e) => setWhen(e.target.value)} />
|
||||
{sun && (
|
||||
<div className="imp-note" data-testid="render-sun">
|
||||
{t("render.sun", { az: sun.azimuth.toFixed(0), el: sun.elevation.toFixed(0) })}
|
||||
@@ -366,6 +371,7 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
<input
|
||||
className="imp-input imp-input-flush"
|
||||
type="text"
|
||||
aria-label={t("render.blenderPath")}
|
||||
data-testid="render-blender-path"
|
||||
style={{ width: "100%" }}
|
||||
placeholder={t("render.blenderPath.placeholder")}
|
||||
@@ -455,7 +461,7 @@ export const RenderDialogHost = memo(function RenderDialogHost() {
|
||||
>
|
||||
{t("render.toLayout")}
|
||||
</button>
|
||||
<button className="imp-btn primary" data-testid="render-save" onClick={() => void savePng()}>
|
||||
<button className="imp-btn primary" data-testid="render-save" data-autofocus onClick={() => void savePng()}>
|
||||
{t("render.save")}
|
||||
</button>
|
||||
</>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Hilfslinien des Layout-Blatts ([208]): Liste mit Position, Löschen und Anlegen per Zahl. Dazu ziehen aus dem Lineal
|
||||
// (LayoutSheet) und Doppelklick auf eine Linie. Die Linien hängen am Masterlayout, nur am Bildschirm sichtbar.
|
||||
|
||||
import { useState } from "react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import type { LayoutGuide } from "../model/types";
|
||||
import { t } from "../i18n";
|
||||
|
||||
@@ -22,6 +22,11 @@ export function SheetGuidesHud({
|
||||
}) {
|
||||
const [axis, setAxis] = useState<"x" | "y">("x");
|
||||
const [pos, setPos] = useState("");
|
||||
// [249] Beim Öffnen ins Positionsfeld (Linie per Zahl anlegen), Esc schliesst, Fokus kehrt zum Knopf zurück (LayoutSheet).
|
||||
const posRef = useRef<HTMLInputElement | null>(null);
|
||||
useEffect(() => {
|
||||
posRef.current?.focus({ preventScroll: true });
|
||||
}, []);
|
||||
const add = () => {
|
||||
const n = parseFloat(pos.replace(",", "."));
|
||||
if (!Number.isFinite(n)) return;
|
||||
@@ -29,14 +34,27 @@ export function SheetGuidesHud({
|
||||
setPos("");
|
||||
};
|
||||
return (
|
||||
<div className="layout-sheet-hud layout-sheet-guides" data-sheet-ui data-testid="guides-hud">
|
||||
<div
|
||||
className="layout-sheet-hud layout-sheet-guides"
|
||||
data-sheet-ui
|
||||
data-testid="guides-hud"
|
||||
role="group"
|
||||
aria-label={t("sheetGuides.title")}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Escape" && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
onClose();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="layout-sheet-hud-title" style={{ display: "flex", justifyContent: "space-between" }}>
|
||||
<span>{t("sheetGuides.title")}</span>
|
||||
<button className="nav-add" onClick={onClose} title={t("sheetGuides.close")}>×</button>
|
||||
<button className="nav-add" data-testid="guides-close" onClick={onClose} title={t("sheetGuides.close")} aria-label={t("sheetGuides.close")}>×</button>
|
||||
</div>
|
||||
<div className="layout-sheet-hud-size">{t("sheetGuides.hint")}</div>
|
||||
<div className="layout-sheet-hud-row">
|
||||
<select className="res-input" data-testid="guide-axis" value={axis} onChange={(e) => setAxis(e.target.value as "x" | "y")}>
|
||||
<select className="res-input" data-testid="guide-axis" aria-label={t("sheetGuides.axis")} value={axis} onChange={(e) => setAxis(e.target.value as "x" | "y")}>
|
||||
<option value="x">{t("sheetGuides.vertical")}</option>
|
||||
<option value="y">{t("sheetGuides.horizontal")}</option>
|
||||
</select>
|
||||
@@ -45,6 +63,8 @@ export function SheetGuidesHud({
|
||||
inputMode="decimal"
|
||||
className="res-input mono num"
|
||||
data-testid="guide-pos"
|
||||
ref={posRef}
|
||||
aria-label={t("sheetGuides.position")}
|
||||
placeholder="mm"
|
||||
value={pos}
|
||||
onChange={(e) => setPos(e.target.value)}
|
||||
@@ -52,7 +72,7 @@ export function SheetGuidesHud({
|
||||
if (e.key === "Enter") add();
|
||||
}}
|
||||
/>
|
||||
<button className="nav-add" data-testid="guide-add" onClick={add}>+</button>
|
||||
<button className="nav-add" data-testid="guide-add" onClick={add} aria-label={t("sheetGuides.add")} title={t("sheetGuides.add")}>+</button>
|
||||
</div>
|
||||
{guides.map((g, i) => (
|
||||
<div key={`${g.axis}-${g.posMm}-${i}`} className="layout-sheet-hud-row" data-guide-row>
|
||||
@@ -63,12 +83,16 @@ export function SheetGuidesHud({
|
||||
step={1}
|
||||
className="res-input mono num"
|
||||
defaultValue={g.posMm}
|
||||
aria-label={t("sheetGuides.rowPosition", { axis: g.axis === "x" ? t("sheetGuides.vertical") : t("sheetGuides.horizontal") })}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === "Enter") (e.target as HTMLInputElement).blur(); // übernimmt den Wert (onBlur)
|
||||
}}
|
||||
onBlur={(e) => {
|
||||
const n = parseFloat(e.target.value);
|
||||
if (Number.isFinite(n) && n !== g.posMm) onMove(i, n);
|
||||
}}
|
||||
/>
|
||||
<button className="nav-add" data-guide-remove title={t("sheetGuides.remove")} onClick={() => onRemove(i)}>
|
||||
<button className="nav-add" data-guide-remove title={t("sheetGuides.remove")} aria-label={t("sheetGuides.remove")} onClick={() => onRemove(i)}>
|
||||
<span className="material-symbols-outlined" aria-hidden="true">delete</span>
|
||||
</button>
|
||||
</span>
|
||||
|
||||
@@ -46,9 +46,10 @@ export function SheetImageHud({
|
||||
}) {
|
||||
const e = edges(image);
|
||||
const dpi = Math.round(imageGeometry(image).dpi);
|
||||
const num = (v: number, set: (n: number) => void, testId?: string) => (
|
||||
const num = (v: number, set: (n: number) => void, testId?: string, label?: string) => (
|
||||
<input
|
||||
type="number"
|
||||
aria-label={label}
|
||||
className="res-input mono num"
|
||||
step={1}
|
||||
data-testid={testId}
|
||||
@@ -60,18 +61,39 @@ export function SheetImageHud({
|
||||
/>
|
||||
);
|
||||
return (
|
||||
<div className="layout-sheet-hud layout-sheet-hud-image" data-sheet-ui data-image-hud data-testid="image-hud">
|
||||
<div
|
||||
className="layout-sheet-hud layout-sheet-hud-image"
|
||||
data-sheet-ui
|
||||
data-image-hud
|
||||
data-testid="image-hud"
|
||||
role="group"
|
||||
aria-label={image.name || t("sheetImage.title")}
|
||||
onKeyDown={(ev) => {
|
||||
// [249] Esc im Feld: Zuschnitt beenden, sonst den Fokus aus dem Feld nehmen (zweites Esc hebt die Auswahl auf).
|
||||
if (ev.key !== "Escape" || ev.ctrlKey || ev.metaKey || ev.altKey) return;
|
||||
const el = ev.target as HTMLElement;
|
||||
if (cropping && onToggleCrop) {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
onToggleCrop();
|
||||
} else if (el.tagName === "INPUT" || el.tagName === "SELECT") {
|
||||
ev.preventDefault();
|
||||
ev.stopPropagation();
|
||||
el.blur();
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="layout-sheet-hud-title">{image.name || t("sheetImage.title")}</div>
|
||||
<div className="layout-sheet-hud-row">
|
||||
<span>X / Y mm</span>
|
||||
<span className="layout-sheet-hud-scale">
|
||||
{num(image.xMm, (xMm) => onPatch({ xMm }), "image-x")}
|
||||
{num(image.yMm, (yMm) => onPatch({ yMm }), "image-y")}
|
||||
{num(image.xMm, (xMm) => onPatch({ xMm }), "image-x", t("sheetImage.x"))}
|
||||
{num(image.yMm, (yMm) => onPatch({ yMm }), "image-y", t("sheetImage.y"))}
|
||||
</span>
|
||||
</div>
|
||||
<div className="layout-sheet-hud-row">
|
||||
<span>{t("sheetImage.width")}</span>
|
||||
<span className="layout-sheet-hud-scale">{num(image.widthMm, (w) => onPatch(resizeImageWidth(image, w)), "image-width")}</span>
|
||||
<span className="layout-sheet-hud-scale">{num(image.widthMm, (w) => onPatch(resizeImageWidth(image, w)), "image-width", t("sheetImage.width"))}</span>
|
||||
</div>
|
||||
<div className="layout-sheet-hud-size">
|
||||
{Math.round(image.widthMm)} × {Math.round(image.heightMm)} mm · {image.pixelWidth} × {image.pixelHeight} px
|
||||
@@ -92,7 +114,7 @@ export function SheetImageHud({
|
||||
<div key={k} className="layout-sheet-hud-row">
|
||||
<span>{t(`sheetImage.crop.${k}`)}</span>
|
||||
<span className="layout-sheet-hud-scale">
|
||||
{num(e[k], (v) => onPatch(cropImage(image, cropFromEdges({ ...e, [k]: v }))), `image-crop-${k}`)}%
|
||||
{num(e[k], (v) => onPatch(cropImage(image, cropFromEdges({ ...e, [k]: v }))), `image-crop-${k}`, t("sheetImage.cropEdge", { edge: t(`sheetImage.crop.${k}`) }))}%
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
@@ -103,7 +125,7 @@ export function SheetImageHud({
|
||||
{t("sheetImage.cropReset")}
|
||||
</button>
|
||||
)}
|
||||
<button className="nav-add" data-testid="image-remove" onClick={onRemove} title={t("sheetImage.remove")}>
|
||||
<button className="nav-add" data-testid="image-remove" onClick={onRemove} title={t("sheetImage.remove")} aria-label={t("sheetImage.remove")}>
|
||||
<span className="material-symbols-outlined" aria-hidden="true">delete</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { setShortcutOverviewOpener } from "../state/shortcutOverviewHook";
|
||||
import { buildShortcutOverview } from "../state/shortcutOverview";
|
||||
import { loadShortcutOverrides } from "../state/keyboardShortcuts";
|
||||
import { loadAliasOverrides } from "../state/commandAliasOverrides";
|
||||
import { useModalFocus } from "./modalFocus";
|
||||
|
||||
export const ShortcutOverviewDialogHost = memo(function ShortcutOverviewDialogHost() {
|
||||
const [open, setOpen] = useState(false);
|
||||
@@ -20,14 +21,8 @@ export const ShortcutOverviewDialogHost = memo(function ShortcutOverviewDialogHo
|
||||
return () => setShortcutOverviewOpener(null);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") setOpen(false);
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [open]);
|
||||
// [249] Fokus ins Suchfeld, Tab-Falle, Esc, Fokus zurück zum Auslöser (Hilfe-Menü).
|
||||
const dialogRef = useModalFocus({ onEscape: () => setOpen(false) });
|
||||
|
||||
const overview = useMemo(() => (open ? buildShortcutOverview(loadShortcutOverrides(), loadAliasOverrides()) : null), [open]);
|
||||
if (!open || !overview) return null;
|
||||
@@ -43,7 +38,7 @@ export const ShortcutOverviewDialogHost = memo(function ShortcutOverviewDialogHo
|
||||
|
||||
return (
|
||||
<div className="imp-overlay" onClick={() => setOpen(false)}>
|
||||
<div className="imp-dialog" role="dialog" aria-modal="true" aria-label={t("help.shortcuts.title")} data-testid="shortcut-overview" onClick={(e) => e.stopPropagation()}>
|
||||
<div ref={dialogRef} className="imp-dialog" role="dialog" aria-modal="true" aria-label={t("help.shortcuts.title")} data-testid="shortcut-overview" onClick={(e) => e.stopPropagation()}>
|
||||
<header className="imp-head">
|
||||
<span className="imp-head-title">{t("help.shortcuts.title")}</span>
|
||||
<button className="imp-close" onClick={() => setOpen(false)} aria-label={t("export.close")}>
|
||||
@@ -55,7 +50,7 @@ export const ShortcutOverviewDialogHost = memo(function ShortcutOverviewDialogHo
|
||||
<input
|
||||
className="imp-input imp-input-flush"
|
||||
type="search"
|
||||
autoFocus
|
||||
data-autofocus
|
||||
value={filter}
|
||||
placeholder={t("help.shortcuts.filter")}
|
||||
aria-label={t("help.shortcuts.filter")}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
// [249] Reine Logik der Dialog-Fokushülle: Tab-Falle, Enter-Felder, Hintergrund-Kürzel-Sperre, Walk-Sperre im Dialog.
|
||||
// Ohne DOM (Umgebung node): Elemente sind Attrappen mit `closest`/`tagName`.
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { enterTriggersPrimary, trapTarget } from "./modalFocus";
|
||||
import { isInModalDialog } from "../state/modalScope";
|
||||
import { walkKeyAllowed } from "../viewport/walk";
|
||||
|
||||
const el = (tag: string, inModal: boolean, extra: Record<string, unknown> = {}) =>
|
||||
({
|
||||
tagName: tag,
|
||||
isContentEditable: false,
|
||||
closest: (sel: string) => (inModal && sel === '[aria-modal="true"]' ? {} : null),
|
||||
...extra,
|
||||
}) as unknown as Element;
|
||||
|
||||
describe("trapTarget (Tab-Falle)", () => {
|
||||
it("springt vom letzten zum ersten und mit Umschalt vom ersten zum letzten", () => {
|
||||
expect(trapTarget(4, 3, false)).toBe(0);
|
||||
expect(trapTarget(4, 0, true)).toBe(3);
|
||||
});
|
||||
it("lässt den Browser innerhalb der Liste springen", () => {
|
||||
expect(trapTarget(4, 1, false)).toBeNull();
|
||||
expect(trapTarget(4, 2, true)).toBeNull();
|
||||
});
|
||||
it("Fokus ausserhalb (Dokument): Tab → erstes, Umschalt+Tab → letztes", () => {
|
||||
expect(trapTarget(3, -1, false)).toBe(0);
|
||||
expect(trapTarget(3, -1, true)).toBe(2);
|
||||
});
|
||||
it("ein einziges Element hält den Fokus fest, keine Elemente: Fokus bleibt am Dialog", () => {
|
||||
expect(trapTarget(1, 0, false)).toBe(0);
|
||||
expect(trapTarget(1, 0, true)).toBe(0);
|
||||
expect(trapTarget(0, -1, false)).toBe(-1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("enterTriggersPrimary", () => {
|
||||
it("nur Texteingaben lösen die Hauptaktion aus, nicht Knöpfe, Auswahlfelder, Haken", () => {
|
||||
expect(enterTriggersPrimary(el("INPUT", true, { type: "number" }))).toBe(true);
|
||||
expect(enterTriggersPrimary(el("INPUT", true, { type: "search" }))).toBe(true);
|
||||
expect(enterTriggersPrimary(el("INPUT", true, { type: "checkbox" }))).toBe(false);
|
||||
expect(enterTriggersPrimary(el("BUTTON", true))).toBe(false);
|
||||
expect(enterTriggersPrimary(el("SELECT", true))).toBe(false);
|
||||
expect(enterTriggersPrimary(null)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Hintergrund-Kürzel im modalen Dialog", () => {
|
||||
it("isInModalDialog erkennt Ziele im Dialog", () => {
|
||||
expect(isInModalDialog(el("BUTTON", true))).toBe(true);
|
||||
expect(isInModalDialog(el("BUTTON", false))).toBe(false);
|
||||
expect(isInModalDialog(null)).toBe(false);
|
||||
});
|
||||
it("Begehen-Tasten gehören dem Dialog, solange der Fokus darin liegt", () => {
|
||||
const k = { ctrlKey: false, metaKey: false };
|
||||
expect(walkKeyAllowed(k, el("BUTTON", true))).toBe(false);
|
||||
expect(walkKeyAllowed(k, el("BUTTON", false))).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,112 @@
|
||||
// [249] Gemeinsame Tastatur-/Fokus-Hülle der Overlay-Dialoge (Kürzel-Übersicht, Kamerafahrt, 3D-Bild, Rendering):
|
||||
// Fokus beim Öffnen ins erste sinnvolle Feld, Tab bleibt im Dialog (Fokus-Falle, auch wenn der Fokus auf dem
|
||||
// Dokument gelandet ist), Esc schliesst, Enter in einem Eingabefeld löst die Hauptaktion aus, nach dem Schliessen
|
||||
// kehrt der Fokus zum Auslöser zurück. Verwendung: `<div className="imp-dialog" role="dialog" aria-modal="true"
|
||||
// ref={useModalFocus({ onEscape, onEnter })}>`. Die Hintergrund-Kürzel sperrt `state/modalScope.ts` über `aria-modal`.
|
||||
|
||||
import { useCallback, useRef } from "react";
|
||||
|
||||
export const FOCUSABLE_SELECTOR =
|
||||
'a[href],button:not([disabled]),input:not([disabled]):not([type="hidden"]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])';
|
||||
|
||||
/**
|
||||
* Tab-Falle: Welches Element soll den Fokus bekommen? `index` = Position des fokussierten Elements in der Tab-Liste
|
||||
* (-1 = ausserhalb). `null` = der Browser darf selbst weiterspringen (Fokus bleibt innen); -1 bei leerer Liste.
|
||||
*/
|
||||
export function trapTarget(count: number, index: number, shift: boolean): number | null {
|
||||
if (count <= 0) return -1;
|
||||
if (index < 0) return shift ? count - 1 : 0;
|
||||
if (!shift && index === count - 1) return 0;
|
||||
if (shift && index === 0) return count - 1;
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Sichtbare, fokussierbare Elemente in Dokumentreihenfolge. */
|
||||
export function focusableIn(root: HTMLElement): HTMLElement[] {
|
||||
return Array.from(root.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(
|
||||
(el) => el.getClientRects().length > 0 && getComputedStyle(el).visibility !== "hidden",
|
||||
);
|
||||
}
|
||||
|
||||
/** Erstes sinnvolles Feld: `[data-autofocus]`, sonst das erste fokussierbare Element ausser dem Schliessen-Kreuz. */
|
||||
export function initialFocusTarget(root: HTMLElement): HTMLElement {
|
||||
const marked = root.querySelector<HTMLElement>("[data-autofocus]:not([disabled])");
|
||||
if (marked) return marked;
|
||||
const list = focusableIn(root);
|
||||
return list.find((el) => !el.classList.contains("imp-close")) ?? list[0] ?? root;
|
||||
}
|
||||
|
||||
/** Enter in diesen Feldern löst die Hauptaktion aus (Knöpfe, Auswahlfelder und mehrzeilige Texte behalten Enter). */
|
||||
export function enterTriggersPrimary(el: Element | null): boolean {
|
||||
if (!el || el.tagName !== "INPUT") return false;
|
||||
const type = (el as HTMLInputElement).type;
|
||||
return type === "text" || type === "number" || type === "search" || type === "email" || type === "url";
|
||||
}
|
||||
|
||||
export interface ModalFocusOptions {
|
||||
/** Esc schliesst; läuft gerade eine Aktion, die Esc nicht verlassen soll, `undefined` lassen. */
|
||||
onEscape?: () => void;
|
||||
/** Hauptaktion bei Enter in einem Eingabefeld. */
|
||||
onEnter?: () => void;
|
||||
}
|
||||
|
||||
/** Callback-Ref für das Dialog-Element (`role="dialog"`). Stabil über Renders; aktuelle Optionen werden mitgeführt. */
|
||||
export function useModalFocus(opts: ModalFocusOptions): (node: HTMLElement | null) => void {
|
||||
const optsRef = useRef(opts);
|
||||
optsRef.current = opts;
|
||||
const cleanup = useRef<(() => void) | null>(null);
|
||||
return useCallback((node: HTMLElement | null) => {
|
||||
cleanup.current?.();
|
||||
cleanup.current = null;
|
||||
if (!node) return;
|
||||
const previous = document.activeElement instanceof HTMLElement ? document.activeElement : null;
|
||||
if (!node.hasAttribute("tabindex")) node.tabIndex = -1;
|
||||
if (!node.contains(document.activeElement)) initialFocusTarget(node).focus({ preventScroll: true });
|
||||
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.defaultPrevented || e.isComposing) return;
|
||||
if (e.key === "Tab" && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||
const list = focusableIn(node);
|
||||
const active = document.activeElement as HTMLElement | null;
|
||||
const to = trapTarget(list.length, active ? list.indexOf(active) : -1, e.shiftKey);
|
||||
if (to === null) return;
|
||||
e.preventDefault();
|
||||
(list[to] ?? node).focus();
|
||||
} else if (e.key === "Escape" && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
||||
const fn = optsRef.current.onEscape;
|
||||
if (!fn) return;
|
||||
e.preventDefault();
|
||||
fn();
|
||||
} else if (e.key === "Enter" && !e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey && !e.repeat) {
|
||||
const fn = optsRef.current.onEnter;
|
||||
if (fn && node.contains(e.target as Node) && enterTriggersPrimary(e.target as Element)) {
|
||||
e.preventDefault();
|
||||
fn();
|
||||
}
|
||||
}
|
||||
};
|
||||
// Wandert der Fokus von aussen in die Seite zurück (z. B. holt sich die Befehlszeile nach dem Befehl, der den
|
||||
// Dialog öffnete, per Zeitgeber den Fokus), kommt er in den Dialog zurück. Ein anderer modaler Dialog darüber ist ausgenommen.
|
||||
let lastInside: HTMLElement | null = null;
|
||||
const onFocusIn = (e: FocusEvent) => {
|
||||
const target = e.target as HTMLElement | null;
|
||||
if (!target) return;
|
||||
if (node.contains(target)) {
|
||||
lastInside = target;
|
||||
} else if (!target.closest?.('[aria-modal="true"]')) {
|
||||
(lastInside?.isConnected ? lastInside : initialFocusTarget(node)).focus({ preventScroll: true });
|
||||
}
|
||||
};
|
||||
document.addEventListener("focusin", onFocusIn);
|
||||
window.addEventListener("keydown", onKey, true);
|
||||
cleanup.current = () => {
|
||||
document.removeEventListener("focusin", onFocusIn);
|
||||
window.removeEventListener("keydown", onKey, true);
|
||||
// Fokus zum Auslöser zurück (nur wenn er noch da ist und der Fokus nicht schon woanders in der Seite liegt).
|
||||
const a = document.activeElement;
|
||||
if (previous && previous.isConnected && (!a || a === document.body || node.contains(a) || !a.isConnected)) {
|
||||
previous.focus({ preventScroll: true });
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
@@ -19,7 +19,8 @@ describe("ViewportToolbar3d", () => {
|
||||
const h = html(false);
|
||||
expect(h).toContain('role="toolbar"');
|
||||
expect(h).toContain('aria-pressed="false"');
|
||||
expect(h).toContain(`aria-label="${t("walk.tip.on")}"`);
|
||||
// [249] Stabiler Name + aria-pressed (kein wechselnder aria-label), der Zustandstext steht im Tooltip.
|
||||
expect(h).toContain(`aria-label="${t("walk.toggle")}"`);
|
||||
expect(h).toContain(`data-tip="${t("walk.tip.on")}"`);
|
||||
expect(h).not.toContain("walk-help");
|
||||
expect(h).not.toContain("is-on");
|
||||
|
||||
@@ -63,7 +63,10 @@ function useThrottledValue<T>(value: T, ms: number, force: boolean): T {
|
||||
|
||||
function ToolButton(props: {
|
||||
icon: string;
|
||||
/** Tooltip (Zustandstext, z. B. „Begehen beenden“). */
|
||||
label: string;
|
||||
/** [249] Stabiler Name für Screenreader; Umschalter melden den Zustand über `aria-pressed`, nicht über wechselnde Namen. */
|
||||
name?: string;
|
||||
testId: string;
|
||||
on?: boolean;
|
||||
pressed?: boolean;
|
||||
@@ -73,7 +76,7 @@ function ToolButton(props: {
|
||||
<button
|
||||
type="button"
|
||||
className={`vp3t-btn${props.on ? " is-on" : ""}`}
|
||||
aria-label={props.label}
|
||||
aria-label={props.name ?? props.label}
|
||||
aria-pressed={props.pressed}
|
||||
data-tip={props.label}
|
||||
data-testid={props.testId}
|
||||
@@ -155,6 +158,7 @@ export function ViewportToolbar3d({ walkMode, onToggleWalk, ghost = false, onTog
|
||||
<ToolButton
|
||||
icon="directions_walk"
|
||||
label={walkMode ? t("walk.tip.off") : t("walk.tip.on")}
|
||||
name={t("walk.toggle")}
|
||||
testId="walk-toggle"
|
||||
on={walkMode}
|
||||
pressed={walkMode}
|
||||
@@ -164,6 +168,7 @@ export function ViewportToolbar3d({ walkMode, onToggleWalk, ghost = false, onTog
|
||||
<ToolButton
|
||||
icon="ghost"
|
||||
label={ghost ? t("walk.tip.ghostOff") : t("walk.tip.ghostOn")}
|
||||
name={t("walk.help.ghost")}
|
||||
testId="walk-ghost"
|
||||
on={ghost}
|
||||
pressed={ghost}
|
||||
|
||||
@@ -114,7 +114,9 @@ export function walkKeyAllowed(e: { ctrlKey: boolean; metaKey: boolean }, active
|
||||
if (!active) return true;
|
||||
const tag = active.tagName;
|
||||
if (tag === "INPUT" || tag === "TEXTAREA" || tag === "SELECT") return false;
|
||||
return !(active as HTMLElement).isContentEditable;
|
||||
if ((active as HTMLElement).isContentEditable) return false;
|
||||
// [249] Liegt der Fokus in einem modalen Dialog, gehören die Tasten dem Dialog (kein Gehen im Hintergrund).
|
||||
return !(typeof active.closest === "function" && active.closest('[aria-modal="true"]'));
|
||||
}
|
||||
|
||||
// ── [245] Kollision und Bodenfolge ─────────────────────────────────────────────────────────────────────────────
|
||||
|
||||
Reference in new issue
Block a user