Skip to content

Commit 3d110fa

Browse files
committed
revert signature change for useEscapeKeydown
1 parent eef857e commit 3d110fa

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

packages/react/use-escape-keydown/src/use-escape-keydown.tsx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,24 @@ import { useDocument } from '@radix-ui/react-document-context';
55
/**
66
* Listens for when the escape key is down
77
*/
8-
function useEscapeKeydown(onEscapeKeyDownProp?: (event: KeyboardEvent) => void) {
8+
function useEscapeKeydown(
9+
onEscapeKeyDownProp?: (event: KeyboardEvent) => void,
10+
ownerDocument?: Document
11+
) {
912
const providedDocument = useDocument();
13+
const document = ownerDocument || providedDocument;
1014
const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
1115

1216
React.useEffect(() => {
13-
if (!providedDocument) return;
17+
const _document = document || globalThis.document;
1418
const handleKeyDown = (event: KeyboardEvent) => {
1519
if (event.key === 'Escape') {
1620
onEscapeKeyDown(event);
1721
}
1822
};
19-
providedDocument.addEventListener('keydown', handleKeyDown, { capture: true });
20-
return () => providedDocument.removeEventListener('keydown', handleKeyDown, { capture: true });
21-
}, [onEscapeKeyDown, providedDocument]);
23+
_document.addEventListener('keydown', handleKeyDown, { capture: true });
24+
return () => _document.removeEventListener('keydown', handleKeyDown, { capture: true });
25+
}, [onEscapeKeyDown, document]);
2226
}
2327

2428
export { useEscapeKeydown };

0 commit comments

Comments
 (0)