From bc58aed0d7443bc5cbdcf22a56d6cbd4efa4339f Mon Sep 17 00:00:00 2001 From: "Timo K." Date: Tue, 8 Sep 2026 13:52:34 +0200 Subject: [PATCH] Keep keyboard shortcuts within Element Call's root MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The call's shortcuts were listened for on the window and allowed whenever focus was inside the standalone app's `#root` — which, for a component embedded in a host, is the host's own root, or nothing. So m, v and space fired while the user typed in the host's composer, and two Element Calls on one page both answered every key. Listen on the element Element Call treats as its root instead (the body standalone, so nothing changes there), and judge whether a key press is spoken for by what has focus — a dialog or a text field — rather than by where it sits in the DOM, since the modals are now portalled to that same root. Co-Authored-By: Claude Fable 5.1 --- src/useCallViewKeyboardShortcuts.test.tsx | 63 +++++++++++++++++- src/useCallViewKeyboardShortcuts.ts | 80 ++++++++++++++--------- 2 files changed, 109 insertions(+), 34 deletions(-) diff --git a/src/useCallViewKeyboardShortcuts.test.tsx b/src/useCallViewKeyboardShortcuts.test.tsx index b002c23e9..fddba5039 100644 --- a/src/useCallViewKeyboardShortcuts.test.tsx +++ b/src/useCallViewKeyboardShortcuts.test.tsx @@ -18,6 +18,7 @@ import { ReactionsRowSize, } from "./reactions"; import { type Controls } from "./controls"; +import { RootElementProvider } from "./RootElementContext"; // Test Explanation: // - The main objective is to test `useCallViewKeyboardShortcuts`. @@ -48,10 +49,11 @@ const TestComponent: FC = ({ ); return ( <> -
+
- {/*// modal lives outside of the root*/} + {/* A dialog, which is what claims key presses for itself; where it + lives in the DOM does not matter */} {modalOpen && ( { // container element that can be interactive and receive focus / keydown // events.