Skip to content

Commit 68c05f6

Browse files
committed
Use documentElement to override cmd+F
1 parent 19f65ff commit 68c05f6

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

packages/react-devtools-shared/src/devtools/views/SearchInput.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ export default function SearchInput({
6464
const handleKeyDown = (event: KeyboardEvent) => {
6565
const {key, metaKey} = event;
6666
if (key === 'f' && metaKey) {
67-
if (inputRef.current !== null) {
68-
inputRef.current.focus();
67+
const inputElement = inputRef.current;
68+
if (inputElement !== null) {
69+
inputElement.focus();
6970
event.preventDefault();
7071
event.stopPropagation();
7172
}
@@ -75,10 +76,14 @@ export default function SearchInput({
7576
// It's important to listen to the ownerDocument to support the browser extension.
7677
// Here we use portals to render individual tabs (e.g. Profiler),
7778
// and the root document might belong to a different window.
78-
const ownerDocument = inputRef.current.ownerDocument;
79-
ownerDocument.addEventListener('keydown', handleKeyDown);
79+
const ownerDocumentElement = inputRef.current.ownerDocument.documentElement;
80+
if (ownerDocumentElement === null) {
81+
return;
82+
}
83+
ownerDocumentElement.addEventListener('keydown', handleKeyDown);
8084

81-
return () => ownerDocument.removeEventListener('keydown', handleKeyDown);
85+
return () =>
86+
ownerDocumentElement.removeEventListener('keydown', handleKeyDown);
8287
}, []);
8388

8489
return (

0 commit comments

Comments
 (0)