Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

design(W2): der Dialog ist jetzt auch ohne Maus einer, und Bewegung ist abschaltbar

Davidc5901d0c6898
diff --git a/src/App.tsx b/src/App.tsx
index fae8c083..42175294 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,4 +1,5 @@
import { useEffect } from 'react'
+import { MotionConfig } from 'framer-motion'
import { AppShell } from './components/layout/AppShell'
import { useSettingsStore } from './stores/settingsStore'
import { useVoiceStore } from './stores/voiceStore'
@@ -57,7 +58,17 @@ function App() {
}
}, [])
- return <AppShell />
+ // „Bewegung reduzieren" respektieren (Audit Welle 2). Die CSS-Regel in
+ // index.css erreicht framer-motion NICHT — das schreibt Transforms per JS
+ // direkt ins style-Attribut, an der Kaskade vorbei. `reducedMotion="user"`
+ // liest dieselbe Systemeinstellung und ersetzt Transform-/Layout-Animationen
+ // durch eine reine Opacity-Blende: die Fläche wandert nicht mehr, der
+ // Zustandswechsel bleibt aber sichtbar (siehe Begründung in index.css).
+ return (
+ <MotionConfig reducedMotion="user">
+ <AppShell />
+ </MotionConfig>
+ )
}
export default App
diff --git a/src/components/chat/AgentModeToggle.tsx b/src/components/chat/AgentModeToggle.tsx
index db01db3d..ffe55a28 100644
--- a/src/components/chat/AgentModeToggle.tsx
+++ b/src/components/chat/AgentModeToggle.tsx
@@ -153,7 +153,7 @@ export function AgentModeToggle() {
</button>
{/* New Chat Required Modal */}
- <Modal open={showNewChatModal} onClose={() => { setShowNewChatModal(false); setNeverShowChecked(false) }} title="">
+ <Modal open={showNewChatModal} onClose={() => { setShowNewChatModal(false); setNeverShowChecked(false) }} title="" ariaLabel="New chat required">
<div className="space-y-4">
<motion.div
initial={{ opacity: 0, y: 10 }}
diff --git a/src/components/chat/AgentWorkspaceDialog.tsx b/src/components/chat/AgentWorkspaceDialog.tsx
index 54d64d78..57e0660d 100644
--- a/src/components/chat/AgentWorkspaceDialog.tsx
+++ b/src/components/chat/AgentWorkspaceDialog.tsx
@@ -130,7 +130,7 @@ export function AgentWorkspaceDialog({
const phase: 'pick' | 'extras' = draft ? 'extras' : 'pick'
return (
- <Modal open={open} onClose={onClose} title="">
+ <Modal open={open} onClose={onClose} title="" ariaLabel="Agent workspace">
<div className="space-y-4">
<div className="text-center space-y-1">
<h3 className="text-base font-semibold text-gray-900 dark:text-white">
diff --git a/src/components/create/WorkflowsModal.tsx b/src/components/create/WorkflowsModal.tsx
index 0d5bdce2..0e957fb2 100644
--- a/src/components/create/WorkflowsModal.tsx
+++ b/src/components/create/WorkflowsModal.tsx
@@ -47,13 +47,10 @@ const INPUT =
* dialog over the Create surface (David 2026-08-02: a window, not a page),
* on the same house Modal the VHS install prompt uses. */
export function WorkflowsModal({ open, onClose }: { open: boolean; onClose: () => void }) {
- useEffect(() => {
- if (!open) return
- const onKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() }
- window.addEventListener('keydown', onKey)
- return () => window.removeEventListener('keydown', onKey)
- }, [open, onClose])
-
+ // Der eigene Escape-Listener ist entfallen: Modal schließt seit Welle 2 selbst
+ // auf Escape, und zwar nur den OBERSTEN Dialog. Der Listener hier hing an
+ // `window` und lief damit an jedem stopPropagation vorbei — er hätte beim
+ // Abbrechen einer Tag-Umbenennung zusätzlich den ganzen Dialog geschlossen.
return (
<Modal open={open} onClose={onClose} title="Workflows & tags" hideHeader maxWidth="max-w-2xl" panelPad="p-0">
<WorkflowsModalInner />
@@ -487,7 +484,15 @@ function WorkflowsModalInner() {
onChange={(e) => setEditingTagName(e.target.value)}
onKeyDown={(e) => {
if (e.key === 'Enter') finishRenameTag()
- if (e.key === 'Escape') setEditingTagId(null)
+ if (e.key === 'Escape') {
+ // Escape bricht ERST das Umbenennen ab, nicht
+ // gleich den ganzen Dialog mit. Modal hört auf
+ // `document`; stopPropagation hält das Ereignis
+ // hier fest, sonst verlöre man zwei Ebenen auf
+ // einen Tastendruck.
+ e.stopPropagation()
+ setEditingTagId(null)
+ }
}}
autoFocus
className={INPUT}
diff --git a/src/components/ui/Modal.tsx b/src/components/ui/Modal.tsx
index f44d78f2..1fc9d4c6 100644
--- a/src/components/ui/Modal.tsx
+++ b/src/components/ui/Modal.tsx
@@ -1,6 +1,17 @@
import { motion, AnimatePresence } from 'framer-motion'
import { X } from 'lucide-react'
-import type { ReactNode } from 'react'
+import { useCallback, useEffect, useId, useRef, type ReactNode } from 'react'
+import {
+ FOCUSABLE_SELECTOR,
+ backgroundNodesToHide,
+ closeDialog,
+ isFocusable,
+ isTopDialog,
+ nextFocusIndex,
+ openDialog,
+ pickInitialFocusIndex,
+} from './dialog-a11y'
+import { SPRING_PANEL } from './motion'
interface Props {
open: boolean
@@ -16,17 +27,142 @@ interface Props {
panelRadius?: string
/** Panel padding (default `p-6`). Override for a tighter dialog. */
panelPad?: string
+ /** Beschriftung für Screenreader, wenn KEIN sichtbarer Titel existiert
+ * (`title=""` oder `hideHeader`). Ohne sie fällt der Dialog auf `title`
+ * bzw. „Dialog" zurück. */
+ ariaLabel?: string
}
// A modal is a real dialog, so it needs an OPAQUE, elevated surface — not the
// transparent `.glass-card` (which is `background: transparent` for inline
// panels). Without this the dialog read straight through to whatever tab was
// behind it and the white title vanished on a light surface.
-export function Modal({ open, onClose, title, children, hideHeader, maxWidth = 'max-w-lg', panelRadius = 'rounded-2xl', panelPad = 'p-6' }: Props) {
+//
+// Bedienbarkeit (Audit Welle 2): das hier war optisch ein Dialog, für Tastatur
+// und Screenreader aber keiner — kein Escape, keine Fokus-Falle, keine Rolle.
+// Wer die Maus nicht benutzt, kam aus dem Ding nicht wieder heraus. Alles unten
+// sitzt bewusst an DIESER einen Stelle, damit die zwölf Einbindungen es erben.
+export function Modal({ open, onClose, title, children, hideHeader, maxWidth = 'max-w-lg', panelRadius = 'rounded-2xl', panelPad = 'p-6', ariaLabel }: Props) {
+ const overlayRef = useRef<HTMLDivElement>(null)
+ const panelRef = useRef<HTMLDivElement>(null)
+ /** Wohin der Fokus beim Schließen zurückkehrt. */
+ const restoreRef = useRef<HTMLElement | null>(null)
+
+ const reactId = useId()
+ const titleId = `${reactId}-title`
+ const hasVisibleTitle = !hideHeader && title.trim().length > 0
+
+ /** Fokussierbare Elemente im Panel, in DOM-Reihenfolge. */
+ const focusables = useCallback((): HTMLElement[] => {
+ const panel = panelRef.current
+ if (!panel) return []
+ return Array.from(panel.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR)).filter(isFocusable)
+ }, [])
+
+ // (1) Stapel-Anmeldung. Muss VOR den Tastatur-Effekten stehen, damit
+ // isTopDialog() bereits stimmt, wenn die Handler scharf werden.
+ useEffect(() => {
+ if (!open) return
+ openDialog(reactId)
+ return () => closeDialog(reactId)
+ }, [open, reactId])
+
+ // (2) Hintergrund inert. Reihenfolge ist wichtig: dieser Effekt wird VOR dem
+ // Fokus-Effekt deklariert, also läuft seine Aufräumfunktion auch zuerst.
+ // Sonst zeigte die Fokus-Rückgabe auf ein noch inertes Element und liefe
+ // ins Leere — `focus()` auf einen inerten Teilbaum ist ein No-op.
+ useEffect(() => {
+ if (!open) return
+ const overlay = overlayRef.current
+ if (!overlay) return
+
+ // Nur Geschwister auf dem Pfad Overlay→<body>, nie ein Vorfahr: der Dialog
+ // hängt im normalen Baum, `aria-hidden` auf #root würde ihn mitverstecken.
+ //
+ // Drei Ausnahmen:
+ // • bereits markierte Knoten (äußeres Modal) werden nicht erneut angefasst,
+ // sonst räumte das innere Modal beim Schließen dem äußeren die Sperre weg;
+ // • ein anderes Dialog-Overlay wird NIE markiert — zwei gleichzeitig
+ // geöffnete Modals sind Geschwister und würden sich sonst gegenseitig
+ // stilllegen, und zwar in Effekt-Reihenfolge, also auch das obere.
+ const marked = backgroundNodesToHide<Element>(overlay, document.body).filter(
+ (el): el is HTMLElement =>
+ el instanceof HTMLElement &&
+ !el.hasAttribute('data-lu-dialog') &&
+ !el.hasAttribute('inert') &&
+ !el.hasAttribute('aria-hidden'),
+ )
+ for (const el of marked) {
+ el.setAttribute('inert', '')
+ el.setAttribute('aria-hidden', 'true')
+ }
+ return () => {
+ for (const el of marked) {
+ el.removeAttribute('inert')
+ el.removeAttribute('aria-hidden')
+ }
+ }
+ }, [open])
+
+ // (3) Fokus hinein — und beim Schließen wieder dorthin zurück, wo er war.
+ // Das Zurückgeben ist der Teil, den man am deutlichsten merkt: ohne ihn
+ // landet der Fokus nach dem Schließen auf <body> und die nächste Tab-Taste
+ // fängt oben in der App wieder von vorn an.
+ useEffect(() => {
+ if (!open) return
+ const active = document.activeElement
+ restoreRef.current = active instanceof HTMLElement && active !== document.body ? active : null
+
+ const items = focusables()
+ const idx = pickInitialFocusIndex(items)
+ if (idx >= 0) items[idx].focus()
+ else panelRef.current?.focus()
+
+ return () => {
+ const target = restoreRef.current
+ restoreRef.current = null
+ if (target && target.isConnected) target.focus()
+ }
+ }, [open, focusables])
+
+ // (4) Escape + Fokus-Falle. Der Listener hängt an `document`, weil der Fokus
+ // nach einem Klick auf nicht-fokussierbaren Text im Panel auf <body>
+ // landet und ein Handler am Panel dann nichts mehr sähe. Kindelemente, die
+ // Escape selbst brauchen (Inline-Umbenennen), stoppen die Propagation und
+ // kommen damit zuerst dran.
+ useEffect(() => {
+ if (!open) return
+ const onKey = (e: KeyboardEvent) => {
+ // Liegen mehrere Dialoge übereinander, reagiert nur der oberste.
+ if (!isTopDialog(reactId)) return
+
+ if (e.key === 'Escape') {
+ e.preventDefault()
+ e.stopPropagation()
+ onClose()
+ return
+ }
+ if (e.key !== 'Tab') return
+
+ const panel = panelRef.current
+ if (!panel) return
+ const items = focusables()
+ const current = items.indexOf(document.activeElement as HTMLElement)
+ const next = nextFocusIndex(items.length, current, e.shiftKey)
+ e.preventDefault()
+ if (next >= 0) items[next].focus()
+ else panel.focus()
+ }
+ document.addEventListener('keydown', onKey)
+ return () => document.removeEventListener('keydown', onKey)
+ }, [open, reactId, onClose, focusables])
+
return (
<AnimatePresence>
{open && (
<motion.div
+ ref={overlayRef}
+ data-lu-dialog
className="fixed inset-0 z-50 flex items-center justify-center p-4"
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
@@ -34,18 +170,26 @@ export function Modal({ open, onClose, title, children, hideHeader, maxWidth = '
>
<div className="absolute inset-0 bg-black/60 backdrop-blur-sm" onClick={onClose} />
<motion.div
+ ref={panelRef}
+ role="dialog"
+ aria-modal="true"
+ {...(hasVisibleTitle
+ ? { 'aria-labelledby': titleId }
+ : { 'aria-label': ariaLabel || title || 'Dialog' })}
+ tabIndex={-1}
className={
- `relative z-10 w-full ${panelRadius} ${panelPad} border border-gray-200 dark:border-white/10 ` +
+ `relative z-10 w-full outline-none ${panelRadius} ${panelPad} border border-gray-200 dark:border-white/10 ` +
'bg-white dark:bg-[#161719] shadow-2xl shadow-black/30 ' + maxWidth
}
initial={{ scale: 0.9, opacity: 0 }}
animate={{ scale: 1, opacity: 1 }}
exit={{ scale: 0.9, opacity: 0 }}
- transition={{ type: 'spring', damping: 25, stiffness: 300 }}
+ transition={SPRING_PANEL}
>
{hideHeader ? (
<button
onClick={onClose}
+ data-dialog-close
className="absolute top-3 right-3 p-1 rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-400 hover:text-gray-700 dark:hover:text-white transition-colors"
aria-label="Close"
>
@@ -53,9 +197,10 @@ export function Modal({ open, onClose, title, children, hideHeader, maxWidth = '
</button>
) : (
<div className="flex items-center justify-between mb-4">
- <h2 className="text-lg font-semibold text-gray-900 dark:text-white">{title}</h2>
+ <h2 id={titleId} className="text-lg font-semibold text-gray-900 dark:text-white">{title}</h2>
<button
onClick={onClose}
+ data-dialog-close
className="p-1 rounded-lg hover:bg-gray-100 dark:hover:bg-white/10 text-gray-400 hover:text-gray-700 dark:hover:text-white transition-colors"
aria-label="Close"
>
diff --git a/src/components/ui/ToggleSwitch.tsx b/src/components/ui/ToggleSwitch.tsx
index 986e49d7..2f852e41 100644
--- a/src/components/ui/ToggleSwitch.tsx
+++ b/src/components/ui/ToggleSwitch.tsx
@@ -1,4 +1,5 @@
import { motion } from 'framer-motion'
+import { SPRING_CONTROL } from './motion'
interface Props {
enabled: boolean
@@ -36,7 +37,7 @@ export function ToggleSwitch({ enabled, onChange, label, disabled = false, size
enabled ? 'bg-green-400' : 'bg-gray-400 dark:bg-gray-500'
}`}
animate={{ left: enabled ? dotTravel : 2 }}
- transition={{ type: 'spring', stiffness: 500, damping: 30 }}
+ transition={SPRING_CONTROL}
/>
</div>
</button>
diff --git a/src/components/ui/__tests__/dialog-a11y.test.ts b/src/components/ui/__tests__/dialog-a11y.test.ts
new file mode 100644
index 00000000..b4275237
--- /dev/null
+++ b/src/components/ui/__tests__/dialog-a11y.test.ts
@@ -0,0 +1,272 @@
+/**
+ * Modal-Bedienbarkeit: Anfangsfokus, Fokus-Falle, Escape-Stapel (Audit Welle 2)
+ *
+ * ui/Modal war optisch ein Dialog, für Tastatur und Screenreader aber keiner:
+ * kein Escape, keine Fokus-Falle, keine Rolle. Wer die Maus nicht benutzt, kam
+ * aus dem Ding nicht wieder heraus.
+ *
+ * Die Testumgebung ist `environment: 'node'` — kein DOM, also lässt sich das
+ * gerenderte Modal nicht anklicken. Deshalb sind die ENTSCHEIDUNGEN aus dem
+ * DOM-Klebstoff herausgezogen (src/components/ui/dialog-a11y.ts) und werden
+ * hier als Verhalten geprüft, nicht als Quelltext gepinnt.
+ *
+ * Run: npx vitest run src/components/ui/__tests__/dialog-a11y.test.ts
+ */
+import { describe, it, expect, beforeEach } from 'vitest'
+import {
+ backgroundNodesToHide,
+ closeDialog,
+ dialogStack,
+ isDestructive,
+ isTopDialog,
+ nextFocusIndex,
+ openDialog,
+ pickInitialFocusIndex,
+ resetDialogStack,
+ type FocusableLike,
+ type TreeNodeLike,
+} from '../dialog-a11y'
+
+/** Baut ein Element-Double in der Minimalform, die die Regeln lesen. */
+function el(spec: { tag?: string; text?: string; disabled?: boolean } & Record<string, unknown>): FocusableLike {
+ const { tag = 'BUTTON', text = '', disabled, ...attrs } = spec
+ return {
+ tagName: tag,
+ textContent: text,
+ ...(disabled === undefined ? {} : { disabled }),
+ getAttribute: (name: string) => (name in attrs ? String(attrs[name]) : null),
+ }
+}
+
+const closeX = el({ tag: 'BUTTON', text: '', 'data-dialog-close': '', 'aria-label': 'Close' })
+
+describe('Anfangsfokus — welches Element ist der sinnvolle Startpunkt', () => {
+ it('wählt im Löschen-Dialog "Cancel", nicht das X und nicht "Delete"', () => {
+ // Die reale Kette aus ModelManager: X, Cancel, Delete.
+ const items = [closeX, el({ text: 'Cancel' }), el({ text: 'Delete' })]
+ expect(pickInitialFocusIndex(items)).toBe(1)
+ })
+
+ it('setzt den Fokus NIE auf einen zerstörenden Knopf, auch wenn er der einzige echte ist', () => {
+ const items = [closeX, el({ text: 'Delete model' })]
+ // Lieber das X als ein "Löschen" unter dem reflexartigen Enter.
+ expect(pickInitialFocusIndex(items)).toBe(0)
+ })
+
+ it('erkennt die deutsche Beschriftung genauso', () => {
+ const items = [closeX, el({ text: 'Abbrechen' }), el({ text: 'Löschen' })]
+ expect(pickInitialFocusIndex(items)).toBe(1)
+ expect(isDestructive(el({ text: 'Löschen' }))).toBe(true)
+ expect(isDestructive(el({ text: 'Zurücksetzen' }))).toBe(true)
+ })
+
+ it('lässt sich per data-destructive korrigieren, wenn die Beschriftung harmlos klingt', () => {
+ const items = [closeX, el({ text: 'OK', 'data-destructive': '' }), el({ text: 'Später' })]
+ expect(pickInitialFocusIndex(items)).toBe(2)
+ })
+
+ it('lässt sich per data-safe entschärfen, wenn die Heuristik danebenliegt', () => {
+ // "Reset filters" löscht keine Daten — der Dialog darf dort starten.
+ const items = [closeX, el({ text: 'Reset filters', 'data-safe': '' })]
+ expect(pickInitialFocusIndex(items)).toBe(1)
+ })
+
+ it('gibt data-autofocus den Vorrang vor der Heuristik', () => {
+ const items = [closeX, el({ text: 'Cancel' }), el({ text: 'Install', 'data-autofocus': '' })]
+ expect(pickInitialFocusIndex(items)).toBe(2)
+ })
+
+ it('landet im Eingabefeld, wenn der Dialog eines hat (Pull Model)', () => {
+ const items = [closeX, el({ tag: 'INPUT', text: '' }), el({ text: 'Pull' })]
+ expect(pickInitialFocusIndex(items)).toBe(1)
+ })
+
+ it('überspringt einen Fließtext-Link zugunsten des ersten Bedienelements', () => {
+ // VHS-Dialog: erst ein Link auf das GitHub-Repo, dann die Knöpfe. Enter
+ // soll den Dialog bedienen, nicht einen Browser aufreißen.
+ const items = [
+ closeX,
+ el({ tag: 'A', href: 'https://github.com/…', text: 'VideoHelperSuite' }),
+ el({ text: 'Install VHS_VideoCombine + continue' }),
+ ]
+ expect(pickInitialFocusIndex(items)).toBe(2)
+ })
+
+ it('nimmt den Link doch, wenn es gar kein Bedienelement gibt', () => {
+ const items = [closeX, el({ tag: 'A', href: 'https://x', text: 'Mehr erfahren' })]
+ expect(pickInitialFocusIndex(items)).toBe(1)
+ })
+
+ it('überspringt deaktivierte und ausgeblendete Elemente', () => {
+ const items = [
+ closeX,
+ el({ text: 'Weiter', disabled: true }),
+ el({ text: 'Später', hidden: '' }),
+ el({ text: 'Jetzt nicht', 'aria-hidden': 'true' }),
+ el({ text: 'Fertig' }),
+ ]
+ expect(pickInitialFocusIndex(items)).toBe(4)
+ })
+
+ it('überspringt tabindex="-1" (programmatisch fokussierbar, aber nicht in der Tab-Kette)', () => {
+ const items = [closeX, el({ text: 'Panel', tabindex: '-1' }), el({ text: 'Weiter' })]
+ expect(pickInitialFocusIndex(items)).toBe(2)
+ })
+
+ it('meldet -1, wenn nichts fokussierbar ist — dann bekommt das Panel den Fokus', () => {
+ expect(pickInitialFocusIndex([])).toBe(-1)
+ expect(pickInitialFocusIndex([el({ text: 'Delete' })])).toBe(-1)
+ })
+})
+
+describe('Fokus-Falle — Tab läuft im Dialog im Kreis', () => {
+ it('Tab geht ein Element weiter', () => {
+ expect(nextFocusIndex(4, 1, false)).toBe(2)
+ })
+
+ it('Tab am letzten Element springt zurück auf das erste (kein Ausbruch)', () => {
+ expect(nextFocusIndex(4, 3, false)).toBe(0)
+ })
+
+ it('Shift+Tab am ersten Element springt ans Ende', () => {
+ expect(nextFocusIndex(4, 0, true)).toBe(3)
+ })
+
+ it('Shift+Tab geht ein Element zurück', () => {
+ expect(nextFocusIndex(4, 2, true)).toBe(1)
+ })
+
+ it('holt einen ausgebüxten Fokus zurück: Tab vorne herein, Shift+Tab hinten', () => {
+ expect(nextFocusIndex(4, -1, false)).toBe(0)
+ expect(nextFocusIndex(4, -1, true)).toBe(3)
+ })
+
+ it('behandelt einen verschwundenen Fokus (Index außerhalb) wie „außerhalb"', () => {
+ expect(nextFocusIndex(3, 99, false)).toBe(0)
+ expect(nextFocusIndex(3, 99, true)).toBe(2)
+ })
+
+ it('bleibt bei einem einzigen Element auf diesem stehen', () => {
+ expect(nextFocusIndex(1, 0, false)).toBe(0)
+ expect(nextFocusIndex(1, 0, true)).toBe(0)
+ })
+
+ it('meldet -1 für einen Dialog ohne fokussierbaren Inhalt', () => {
+ expect(nextFocusIndex(0, -1, false)).toBe(-1)
+ expect(nextFocusIndex(0, 0, true)).toBe(-1)
+ })
+})
+
+describe('Escape-Stapel — Escape schließt das oberste Modal, nicht alle', () => {
+ beforeEach(resetDialogStack)
+
+ it('ein einzelner Dialog ist der oberste', () => {
+ openDialog('a')
+ expect(isTopDialog('a')).toBe(true)
+ })
+
+ it('bei zwei Dialogen reagiert nur der zuletzt geöffnete', () => {
+ openDialog('a')
+ openDialog('b')
+ expect(isTopDialog('b')).toBe(true)
+ expect(isTopDialog('a')).toBe(false)
+ })
+
+ it('nach dem Schließen des obersten ist der darunter wieder dran', () => {
+ openDialog('a')
+ openDialog('b')
+ closeDialog('b')
+ expect(isTopDialog('a')).toBe(true)
+ })
+
+ it('das Schließen eines mittleren Dialogs ändert nichts am obersten', () => {
+ openDialog('a')
+ openDialog('b')
+ openDialog('c')
+ closeDialog('b')
+ expect(isTopDialog('c')).toBe(true)
+ expect(dialogStack()).toEqual(['a', 'c'])
+ })
+
+ it('zweimaliges Anmelden derselben ID legt sie nicht doppelt ab (StrictMode)', () => {
+ openDialog('a')
+ openDialog('a')
+ expect(dialogStack()).toEqual(['a'])
+ closeDialog('a')
+ expect(dialogStack()).toEqual([])
+ })
+
+ it('das erneute Anmelden hebt einen Dialog nach oben', () => {
+ openDialog('a')
+ openDialog('b')
+ openDialog('a')
+ expect(isTopDialog('a')).toBe(true)
+ })
+
+ it('ein unbekanntes Abmelden ist ein No-op', () => {
+ openDialog('a')
+ closeDialog('unbekannt')
+ expect(dialogStack()).toEqual(['a'])
+ })
+
+ it('ohne offenen Dialog ist niemand oberster', () => {
+ expect(isTopDialog('a')).toBe(false)
+ })
+})
+
+describe('Hintergrund inert — ohne den Dialog selbst mitzuverstecken', () => {
+ interface FakeNode extends TreeNodeLike {
+ name: string
+ parentElement: FakeNode | null
+ children: FakeNode[]
+ }
+
+ function node(name: string, children: FakeNode[] = []): FakeNode {
+ const n: FakeNode = { name, parentElement: null, children }
+ for (const c of children) c.parentElement = n
+ return n
+ }
+
+ const names = (ns: FakeNode[]) => ns.map((n) => n.name).sort()
+
+ it('sammelt die Geschwister auf dem Weg nach oben ein, aber keinen Vorfahren', () => {
+ const dialog = node('dialog')
+ const sidebar = node('sidebar')
+ const main = node('main', [node('chat'), dialog])
+ const root = node('root', [sidebar, main])
+ const body = node('body', [root, node('portal-root')])
+
+ const hidden = backgroundNodesToHide(dialog, body)
+
+ expect(names(hidden)).toEqual(['chat', 'portal-root', 'sidebar'])
+ // Der Dialog selbst und seine Vorfahren dürfen NIE dabei sein — genau der
+ // Fehler, den `aria-hidden` auf #root produziert.
+ for (const forbidden of ['dialog', 'main', 'root', 'body']) {
+ expect(names(hidden)).not.toContain(forbidden)
+ }
+ })
+
+ it('hört bei stopAt auf und fasst dessen Vorfahren nicht mehr an', () => {
+ const dialog = node('dialog')
+ const root = node('root', [node('sidebar'), dialog])
+ const body = node('body', [root, node('script')])
+ node('html', [node('head'), body])
+
+ const hidden = backgroundNodesToHide(dialog, root)
+
+ expect(names(hidden)).toEqual(['sidebar'])
+ expect(names(hidden)).not.toContain('script')
+ expect(names(hidden)).not.toContain('head')
+ })
+
+ it('kommt mit einem Dialog direkt unter stopAt zurecht', () => {
+ const dialog = node('dialog')
+ const body = node('body', [node('root'), dialog])
+
+ expect(names(backgroundNodesToHide(dialog, body))).toEqual(['root'])
+ })
+
+ it('liefert nichts, wenn der Dialog gar nicht eingehängt ist', () => {
+ expect(backgroundNodesToHide(node('dialog'), null)).toEqual([])
+ })
+})
diff --git a/src/components/ui/dialog-a11y.ts b/src/components/ui/dialog-a11y.ts
new file mode 100644
index 00000000..48510f73
--- /dev/null
+++ b/src/components/ui/dialog-a11y.ts
@@ -0,0 +1,205 @@
+/**
+ * Dialog-Tastaturregeln als reine Funktionen.
+ *
+ * Die Testumgebung ist `environment: 'node'` — es gibt kein DOM, also lässt
+ * sich ein gerendertes Modal nicht anklicken. Alles, was OHNE Dokument
+ * entschieden werden kann, liegt deshalb hier und ist als Verhalten testbar:
+ * welches Element den Anfangsfokus bekommt, wohin Tab/Shift+Tab laufen,
+ * welcher Dialog auf Escape reagiert, wenn mehrere übereinander liegen, und
+ * welche Knoten für Screenreader ausgeblendet werden dürfen, ohne den Dialog
+ * selbst mit auszublenden.
+ *
+ * Modal.tsx hält nur noch den DOM-Klebstoff (querySelectorAll, .focus(),
+ * addEventListener) — die Entscheidungen fallen alle hier.
+ */
+
+/** CSS-Selektor für alles, was grundsätzlich Fokus annehmen kann. */
+export const FOCUSABLE_SELECTOR =
+ 'a[href], button, input, select, textarea, summary, [contenteditable]:not([contenteditable="false"]), [tabindex]'
+
+/**
+ * Minimalform eines fokussierbaren Elements — genau das, was die Regeln unten
+ * lesen. `HTMLElement` erfüllt sie strukturell, deshalb übergibt der Browser-
+ * Code echte Elemente und der Node-Test schlichte Objekte.
+ */
+export interface FocusableLike {
+ readonly tagName?: string
+ readonly disabled?: boolean
+ readonly textContent?: string | null
+ getAttribute(name: string): string | null
+}
+
+/**
+ * Wörter, die einen Knopf als „macht etwas kaputt" ausweisen. Ein solcher Knopf
+ * darf beim Öffnen NIE vorausgewählt sein: wer den Dialog mit der Tastatur
+ * öffnet und reflexartig Enter drückt, hat sonst gelöscht.
+ * Deutsch + Englisch, weil die Oberfläche gemischt beschriftet ist.
+ */
+export const DESTRUCTIVE_LABEL =
+ /(delete|remove|discard|erase|reset|uninstall|wipe|destroy|overwrite|revoke|l(ö|oe)schen|entfernen|verwerfen|zur(ü|ue)cksetzen|überschreiben)/i
+
+function labelOf(el: FocusableLike): string {
+ return [el.getAttribute('aria-label'), el.getAttribute('data-label'), el.textContent]
+ .filter((s): s is string => typeof s === 'string')
+ .join(' ')
+}
+
+/** Ist das Element ein zerstörender Knopf? `data-destructive` schlägt Heuristik. */
+export function isDestructive(el: FocusableLike): boolean {
+ if (el.getAttribute('data-destructive') !== null) return true
+ if (el.getAttribute('data-safe') !== null) return false
+ return DESTRUCTIVE_LABEL.test(labelOf(el))
+}
+
+/** Der X-Knopf des Dialogs selbst — fokussierbar, aber ein armseliger Startpunkt. */
+export function isDialogCloseButton(el: FocusableLike): boolean {
+ return el.getAttribute('data-dialog-close') !== null
+}
+
+/**
+ * Ein Link im Fließtext („…siehe Kosinkadink/VideoHelperSuite") ist zwar
+ * fokussierbar, aber als Startpunkt falsch: reflexartiges Enter reißt einen
+ * Browser auf, statt den Dialog zu bedienen. Er kommt erst dran, wenn es im
+ * Dialog gar kein Bedienelement gibt.
+ */
+export function isInlineLink(el: FocusableLike): boolean {
+ return el.tagName?.toUpperCase() === 'A' && el.getAttribute('href') !== null
+}
+
+/** Deaktivierte/versteckte Elemente nehmen keinen Fokus an. */
+export function isFocusable(el: FocusableLike): boolean {
+ if (el.disabled === true) return false
+ if (el.getAttribute('disabled') !== null) return false
+ if (el.getAttribute('hidden') !== null) return false
+ if (el.getAttribute('aria-hidden') === 'true') return false
+ if (el.getAttribute('inert') !== null) return false
+ const tabindex = el.getAttribute('tabindex')
+ if (tabindex !== null && Number(tabindex) < 0) return false
+ return true
+}
+
+/**
+ * Welches Element bekommt beim Öffnen den Fokus?
+ *
+ * Reihenfolge:
+ * 1. ein ausdrückliches `data-autofocus` (der Aufrufer weiß es besser),
+ * 2. sonst das erste Bedienelement, das weder Schließen-X noch zerstörend
+ * noch ein Fließtext-Link ist,
+ * 3. sonst der erste Fließtext-Link (besser als nichts),
+ * 4. sonst das Schließen-X (besser als ein „Löschen" unter dem Finger),
+ * 5. sonst gar keins → der Aufrufer fokussiert das Panel selbst.
+ *
+ * @returns Index in `candidates`, oder -1 für „nimm das Panel".
+ */
+export function pickInitialFocusIndex(candidates: readonly FocusableLike[]): number {
+ const usable = candidates.map(isFocusable)
+ const plain = (i: number) => usable[i] && !isDialogCloseButton(candidates[i]) && !isDestructive(candidates[i])
+
+ const explicit = candidates.findIndex((c, i) => usable[i] && c.getAttribute('data-autofocus') !== null)
+ if (explicit >= 0) return explicit
+
+ const control = candidates.findIndex((c, i) => plain(i) && !isInlineLink(c))
+ if (control >= 0) return control
+
+ const link = candidates.findIndex((_, i) => plain(i))
+ if (link >= 0) return link
+
+ const close = candidates.findIndex((c, i) => usable[i] && isDialogCloseButton(c))
+ if (close >= 0) return close
+
+ return -1
+}
+
+/**
+ * Fokus-Falle: wohin springt Tab (bzw. Shift+Tab) als Nächstes?
+ *
+ * `current` ist der Index des gerade fokussierten Elements oder -1, wenn der
+ * Fokus außerhalb der Liste steht (Panel selbst, oder er ist ausgebüxt) — dann
+ * holt Tab ihn vorne, Shift+Tab hinten wieder herein.
+ *
+ * @returns Zielindex, oder -1 wenn es nichts zu fokussieren gibt.
+ */
+export function nextFocusIndex(count: number, current: number, backwards: boolean): number {
+ if (count <= 0) return -1
+ if (current < 0 || current >= count) return backwards ? count - 1 : 0
+ return backwards ? (current - 1 + count) % count : (current + 1) % count
+}
+
+/* ── Escape-Stapel ────────────────────────────────────────────────────────
+ Mehrere Modals können gleichzeitig offen sein (Modell löschen → Fehler-
+ Dialog). Jeder Dialog hört auf `document`, also würden ohne Stapel ALLE auf
+ ein Escape reagieren und der Nutzer verlöre zwei Ebenen auf einen Schlag.
+ Nur der zuletzt geöffnete gilt als oberster.
+ ──────────────────────────────────────────────────────────────────────── */
+
+const stack: string[] = []
+
+/** Meldet einen Dialog als offen an; er wird damit zum obersten. */
+export function openDialog(id: string): void {
+ closeDialog(id)
+ stack.push(id)
+}
+
+/** Meldet einen Dialog ab. Unbekannte IDs sind ein No-op (StrictMode-fest). */
+export function closeDialog(id: string): void {
+ const i = stack.lastIndexOf(id)
+ if (i >= 0) stack.splice(i, 1)
+}
+
+/** Nur der oberste Dialog darf auf Escape und Tab reagieren. */
+export function isTopDialog(id: string): boolean {
+ return stack.length > 0 && stack[stack.length - 1] === id
+}
+
+/** Momentaufnahme des Stapels, unterste zuerst (Diagnose + Tests). */
+export function dialogStack(): readonly string[] {
+ return [...stack]
+}
+
+/** Nur für Tests: Stapel leeren. */
+export function resetDialogStack(): void {
+ stack.length = 0
+}
+
+/* ── Hintergrund inert ──────────────────────────────────────────────────── */
+
+/**
+ * Minimalform eines DOM-Knotens für den Geschwister-Lauf. `Element` erfüllt sie.
+ */
+export interface TreeNodeLike {
+ readonly parentElement: TreeNodeLike | null
+ readonly children: ArrayLike<TreeNodeLike>
+}
+
+/**
+ * Welche Knoten dürfen ausgeblendet werden (`inert` / `aria-hidden`), solange
+ * der Dialog offen ist?
+ *
+ * Der Dialog hängt im normalen React-Baum, NICHT in einem Portal. `aria-hidden`
+ * auf `#root` würde ihn deshalb mitverstecken — genau der Fehler, den man in
+ * freier Wildbahn ständig sieht. Also werden nur die GESCHWISTER auf dem Pfad
+ * vom Dialog bis `stopAt` eingesammelt; kein Vorfahr des Dialogs und der Dialog
+ * selbst schon gar nicht.
+ *
+ * @param node Wurzelknoten des Dialogs (der Overlay-Container).
+ * @param stopAt Oberste Ebene, deren Geschwister noch behandelt werden
+ * (üblicherweise `document.body`); danach wird abgebrochen.
+ */
+export function backgroundNodesToHide<T extends TreeNodeLike>(node: T, stopAt: TreeNodeLike | null): T[] {
+ const out: T[] = []
+ let onPath: TreeNodeLike = node
+ let parent: TreeNodeLike | null = node.parentElement
+
+ while (parent) {
+ const kids = parent.children
+ for (let i = 0; i < kids.length; i++) {
+ const child = kids[i]
+ if (child !== onPath) out.push(child as T)
+ }
+ if (parent === stopAt) break
+ onPath = parent
+ parent = parent.parentElement
+ }
+
+ return out
+}
diff --git a/src/components/ui/motion.ts b/src/components/ui/motion.ts
new file mode 100644
index 00000000..1afca897
--- /dev/null
+++ b/src/components/ui/motion.ts
@@ -0,0 +1,45 @@
+import type { Transition } from 'framer-motion'
+
+/**
+ * Motion-Leiter — die JS-Seite der vier `--motion-*` Tokens aus index.css.
+ *
+ * framer-motion liest keine CSS-Variablen, deshalb existiert die Leiter zweimal:
+ * einmal als CSS-Token (für `transition-*`/Tailwind) und einmal hier (für
+ * `motion.*`-Transitions). Die Zahlen sind NICHT neu erfunden, sondern die im
+ * Code tatsächlich gemessenen Werte, verdichtet auf drei Stufen:
+ *
+ * 0.12s ×12 Vorkommen → fast (Mikro-Feedback: Hover, Toggle, Badge)
+ * 0.15s ×21 Vorkommen → base (Haus-Standard: Ein-/Ausblenden, Listen)
+ * 0.20s ×7 Vorkommen → „ (auf base gerundet)
+ * 0.30s ×5 Vorkommen → slow (Flächen: Dialog, Panel, Slide-over)
+ *
+ * Wer eine neue Animation baut, nimmt eine dieser Stufen statt einer vierten Zahl.
+ */
+export const MOTION_MS = {
+ /** --motion-fast: Mikro-Feedback, darf nicht „animiert" wirken. */
+ fast: 120,
+ /** --motion-base: Haus-Standard für Ein-/Ausblendungen. */
+ base: 150,
+ /** --motion-slow: große Flächen (Dialog, Slide-over). */
+ slow: 300,
+} as const
+
+/** Sekunden statt Millisekunden — framer-motion rechnet in Sekunden. */
+export const MOTION_S = {
+ fast: MOTION_MS.fast / 1000,
+ base: MOTION_MS.base / 1000,
+ slow: MOTION_MS.slow / 1000,
+} as const
+
+/**
+ * Panel-Feder — Dialogflächen (Modal). Werte unverändert aus Modal.tsx
+ * übernommen (damping 25 / stiffness 300 ≈ 300 ms Einschwingen, also
+ * --motion-slow); benannt, damit die nächste Fläche nicht wieder rät.
+ */
+export const SPRING_PANEL = { type: 'spring', damping: 25, stiffness: 300 } as const satisfies Transition
+
+/**
+ * Control-Feder — kleine Bedienelemente (ToggleSwitch-Knopf). Werte unverändert
+ * aus ToggleSwitch.tsx (stiffness 500 / damping 30 ≈ 150 ms, also --motion-base).
+ */
+export const SPRING_CONTROL = { type: 'spring', stiffness: 500, damping: 30 } as const satisfies Transition
diff --git a/src/hooks/useKeyboardShortcuts.ts b/src/hooks/useKeyboardShortcuts.ts
index 5a48e48b..77d5804c 100644
--- a/src/hooks/useKeyboardShortcuts.ts
+++ b/src/hooks/useKeyboardShortcuts.ts
@@ -7,6 +7,10 @@
* Ctrl+/ — Show shortcuts help
* Ctrl+Shift+D — Toggle dark/light mode
* Escape — Close any open panel/modal
+ *
+ * Escape wird NICHT hier behandelt: seit Welle 2 schließt ui/Modal sich selbst
+ * und kennt dabei den Dialog-Stapel, schließt also nur den obersten. Ein
+ * zweiter Escape-Handler an dieser Stelle würde zwei Ebenen auf einmal zumachen.
*/
import { useEffect, useCallback } from 'react'
@@ -16,15 +20,66 @@ import { useSettingsStore } from '../stores/settingsStore'
import { useUIStore } from '../stores/uiStore'
import { exportConversation } from '../lib/chat-export'
+/** Die Teilmenge eines KeyboardEvent, die der Besitz-Entscheidung reicht. */
+export interface ShortcutKeyEvent {
+ readonly key: string
+ readonly ctrlKey: boolean
+ readonly metaKey: boolean
+}
+
+/**
+ * Tastenkombinationen, die IMMER dem fokussierten Textfeld gehören — die
+ * Bearbeitungsbefehle des Systems. Ohne diese Liste würde ein Kürzel-Handler,
+ * der Modifier-Tasten auch im Eingabefeld auswertet, Cmd+A/C/V/X/Z schlucken.
+ */
+export const EDITING_KEYS = new Set(['a', 'c', 'v', 'x', 'z', 'y'])
+
+const NAV_KEYS = new Set(['ArrowLeft', 'ArrowRight', 'ArrowUp', 'ArrowDown', 'Home', 'End', 'Backspace', 'Delete'])
+
+/**
+ * Wem gehört dieser Tastendruck: der App (globales Kürzel) oder dem Feld?
+ *
+ * Vorher stand die `isCtrl`-Prüfung HINTER dem Eingabefeld-Guard, also wurde
+ * jedes Kürzel mit Modifier verschluckt, solange irgendein Feld den Fokus
+ * hatte — und in dieser App hat fast immer das Chat-Eingabefeld den Fokus.
+ * Ctrl+N/Ctrl+E waren damit praktisch tot.
+ *
+ * Umgekehrt darf das Vorziehen das Tippen nicht kaputtmachen, deshalb die
+ * beiden Ausnahmen unten.
+ */
+export function shortcutOwner(e: ShortcutKeyEvent, inInput: boolean, isMac: boolean): 'app' | 'field' {
+ if (e.key === 'Escape') return 'app'
+ if (!inInput) return 'app'
+
+ const isCtrl = e.ctrlKey || e.metaKey
+ if (!isCtrl) return 'field'
+
+ // (1) Bearbeitungsbefehle: Cmd/Ctrl + A C V X Z Y und die Navigationstasten
+ // bleiben beim Feld, sonst kann man im Textfeld nicht mehr arbeiten.
+ if (EDITING_KEYS.has(e.key.toLowerCase())) return 'field'
+ if (NAV_KEYS.has(e.key)) return 'field'
+
+ // (2) macOS: in Textfeldern sind die Ctrl-Tasten die Emacs-Bindings des
+ // Systems (Ctrl+E = Zeilenende, Ctrl+N = Zeile runter, Ctrl+A = Anfang).
+ // Die App-Kürzel laufen dort ohnehin über Cmd, also bekommt Ctrl-ohne-Cmd
+ // das Feld zurück und die Cursorbewegung bleibt heil.
+ if (isMac && e.ctrlKey && !e.metaKey) return 'field'
+
+ return 'app'
+}
+
+const IS_MAC = typeof navigator !== 'undefined' && /Mac|iPhone|iPad/i.test(navigator.userAgent || '')
+
export function useKeyboardShortcuts() {
const handleKeyDown = useCallback((e: KeyboardEvent) => {
const isCtrl = e.ctrlKey || e.metaKey
const isShift = e.shiftKey
const tag = (e.target as HTMLElement).tagName
- // Don't interfere with input fields (except for Escape)
+ // Don't interfere with input fields — but a shortcut WITH a modifier is not
+ // typing, so it is decided by shortcutOwner() instead of a blanket return.
const inInput = tag === 'INPUT' || tag === 'TEXTAREA' || (e.target as HTMLElement).isContentEditable
- if (inInput && e.key !== 'Escape') return
+ if (shortcutOwner(e, inInput, IS_MAC) === 'field') return
// Ctrl+N — New conversation
if (isCtrl && e.key === 'n') {
diff --git a/src/index.css b/src/index.css
index 4d84388c..f4a933e3 100644
--- a/src/index.css
+++ b/src/index.css
@@ -42,6 +42,25 @@
--color-lu-accent-hover: #b1a6ff;
--color-lu-accent-soft: rgba(160, 148, 248, 0.14);
--color-lu-accent-ring: rgba(160, 148, 248, 0.55);
+
+ /* ── Motion — eine benannte Leiter statt verstreuter Zahlen ──
+ Dauer und Kurve standen bisher als Literale in den Komponenten. Erhoben
+ wurde, was tatsächlich benutzt wird (framer-motion + Tailwind, Stand 2.6.7):
+
+ 0.12s ×12 → --motion-fast Mikro-Feedback (Hover, Toggle, Badge)
+ 0.15s ×21 → --motion-base Haus-Standard (Ein-/Ausblenden, Listen)
+ 0.20s ×7 → --motion-base (auf den Standard gerundet)
+ 0.30s ×5 → --motion-slow Flächen (Dialog, Panel, Slide-over)
+
+ --motion-ease ist die Kurve, die `ease-out`/`transition-colors` in diesem
+ Haus meinen: schnell los, weich aus. Vier Tokens, mehr braucht die App
+ nicht — wer eine fünfte Dauer will, nimmt eine dieser Stufen.
+ Die JS-Seite (framer-motion liest keine CSS-Variablen) spiegelt die
+ gleiche Leiter in src/components/ui/motion.ts. */
+ --motion-fast: 120ms;
+ --motion-base: 150ms;
+ --motion-slow: 300ms;
+ --motion-ease: cubic-bezier(0.2, 0, 0, 1);
}
/* ─────────────────────────────────────────────────────────────────────
@@ -473,3 +492,55 @@ input[type="range"]::-webkit-slider-thumb {
40% { opacity: 1; }
}
.lu-band-dot { animation: lu-band-dot 1.2s ease-in-out infinite; }
+
+/* ─────────────────────────────────────────────────────────────────────
+ „Bewegung reduzieren" respektieren (Audit Welle 2)
+
+ Für einen Teil der Nutzer ist das keine Geschmacksfrage: großflächige
+ Bewegung löst Übelkeit und Schwindel aus. Bisher lief trotz gesetzter
+ Systemeinstellung die volle Animation.
+
+ ENTSCHEIDUNG: nicht auf null. Ein Dialog, der ohne jede Andeutung
+ dasteht, liest sich wie ein Darstellungsfehler — man sieht nicht, ob er
+ gerade aufging oder schon die ganze Zeit da war. Stattdessen wird alles
+ auf eine sehr kurze Ein-/Ausblendung zusammengezogen (--motion-fast,
+ 120 ms, linear): kurz genug, dass nichts mehr über den Schirm wandert,
+ lang genug, dass die Zustandsänderung sichtbar bleibt.
+
+ Endlos laufende Zierde (Shimmer, pulsierende Punkte) wird dagegen ganz
+ angehalten — Dauerbewegung hat keine Rückmeldefunktion, sie ist nur
+ Dekoration, und genau sie ist das Problem.
+
+ framer-motion animiert an CSS vorbei (inline Transforms per JS), diese
+ Regel erreicht es also NICHT. Dafür sitzt <MotionConfig reducedMotion="user">
+ an der App-Wurzel (src/App.tsx).
+ ───────────────────────────────────────────────────────────────────── */
+@media (prefers-reduced-motion: reduce) {
+ *,
+ *::before,
+ *::after {
+ transition-duration: var(--motion-fast) !important;
+ transition-timing-function: linear !important;
+ /* `iteration-count: 1` beendet auch Dauerschleifen. Ohne das würde die
+ gekürzte Dauer aus einem 1,6-s-Shimmer ein Stroboskop mit acht Durch-
+ läufen pro Sekunde machen — schlimmer als der Ausgangszustand. */
+ animation-duration: var(--motion-fast) !important;
+ animation-iteration-count: 1 !important;
+ animation-timing-function: linear !important;
+ scroll-behavior: auto !important;
+ }
+
+ /* AUSNAHME: der Ladekringel ist keine Zierde, er ist die einzige Auskunft
+ darüber, dass die App noch arbeitet und nicht hängt. Er läuft weiter,
+ aber langsam und gleichförmig (1,5 s statt 1 s) — eine kleine, ortsfeste
+ Drehung ist vestibulär unkritisch, ein eingefrorener Spinner dagegen
+ eine Falschaussage. Gleiches gilt für die Skelett-Pulse. */
+ .animate-spin {
+ animation-duration: 1.5s !important;
+ animation-iteration-count: infinite !important;
+ }
+ .animate-pulse {
+ animation-duration: 3s !important;
+ animation-iteration-count: infinite !important;
+ }
+}