Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

fix: escape key handling compatibility issue with blocksuite (#7365)

pengx1734b6a3bf1f3a
diff --git a/packages/frontend/core/src/modules/peek-view/view/modal-container.tsx b/packages/frontend/core/src/modules/peek-view/view/modal-container.tsx
index 72b865bb70..d8d4b063a8 100644
--- a/packages/frontend/core/src/modules/peek-view/view/modal-container.tsx
+++ b/packages/frontend/core/src/modules/peek-view/view/modal-container.tsx
@@ -22,6 +22,11 @@ const contentOptions: Dialog.DialogContentProps = {
e.preventDefault();
}
},
+ onEscapeKeyDown: e => {
+ // prevent closing the modal when pressing escape key by default
+ // this is because radix-ui register the escape key event on the document using capture, which is not possible to prevent in blocksuite
+ e.preventDefault();
+ },
style: {
padding: 0,
backgroundColor: 'transparent',
@@ -105,6 +110,18 @@ export const PeekViewModalContainer = forwardRef<
});
}, [open]);
+ useEffect(() => {
+ const onKeyDown = (e: KeyboardEvent) => {
+ if (e.key === 'Escape') {
+ onOpenChange(false);
+ }
+ };
+ document.addEventListener('keydown', onKeyDown);
+ return () => {
+ document.removeEventListener('keydown', onKeyDown);
+ };
+ }, [onOpenChange]);
+
useEffect(() => {
const bondingBox = target ? getElementScreenPositionCenter(target) : null;
const offsetLeft =