fix(keyboard): forward iframe keydown events to parent window#46
fix(keyboard): forward iframe keydown events to parent window#46chasel34 wants to merge 2 commits into
Conversation
|
Thanks for the PR. I checked a local rebase onto the latest What I found:
Suggested next step:
Recommended validation:
|
When a slide or preview iframe receives focus, keydown events fire in the iframe's own browsing context and never reach the parent window's listener. This broke arrow-key navigation and the fullscreen shortcut (f/F) in DeckViewer, and the fullscreen shortcut in PreviewPane. Fix: on each iframe's onLoad, attach a keydown listener to its contentWindow that re-dispatches the event on the parent window. A shared isEditableTarget() helper (src/lib/iframe-key.ts) guards against forwarding keys typed into INPUT/TEXTAREA/contentEditable controls. The naive `instanceof HTMLElement` check is intentionally avoided — it fails across window realms because the element's prototype chain belongs to the iframe's HTMLElement, not the parent's. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ontract Covers both sides of the isEditableTarget guard: - ArrowRight / f from a plain element are forwarded to the parent window - ArrowRight / f from an iframe <input> or contenteditable are blocked - N from a deck iframe body shows the DeckViewer notes panel; N from an iframe <input> leaves the panel visible (guard blocks the toggle-back) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
ba9be65 to
af42f9e
Compare
|
Rebased onto Rebase — Git auto-detected the directory rename; all three files landed correctly:
The Tests — Covers both sides of the
One fixture correction discovered during the run: Verification: |
Problem
Clicking inside a slide or preview iframe moves keyboard focus into the
iframe's own browsing context. The parent page's
window.addEventListener("keydown", …)never receives those events, so arrow-key navigation, the notes toggle (N),
and the fullscreen shortcut (F) all stop working as soon as the iframe is focused.
Fix
On each iframe's
onLoad, attach akeydownlistener to itscontentWindowthat re-dispatches the event on the parent
window. No manual cleanup needed:both iframes are keyed (
key=…) and fully remount on content changes,destroying old listeners automatically.
src/lib/iframe-key.ts— shared helperisEditableTarget(target)guardsthe forwarder against leaking keys typed into
<input>,<textarea>, orcontenteditablecontrols inside a slide. It checkstagNameandisContentEditabledirectly rather thaninstanceof HTMLElement, which wouldalways return
falseacross window realms.Test plan
fullscreen, N toggles notes.
<input>inside a slide → no navigation or fullscreen side-effects.pnpm buildpasses with no type errors.🤖 Generated with Claude Code