mirror of
https://github.com/toeverything/AFFiNE.git
synced 2024-12-02 14:33:54 +03:00
fix: escape key handling compatibility issue with blocksuite (#7365)
fix PD-1347 See https://github.com/radix-ui/primitives/blob/main/packages/react/use-escape-keydown/src/useEscapeKeydown.tsx#L19-L20 This behavior in radix-ui is not possible to be prevented since escape keydown is bound to document with capturing, unless dialogs in blocksuite is also implemented with radix-ui.
This commit is contained in:
parent
eca484dc28
commit
34b6a3bf1f
@ -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 =
|
||||
|
Loading…
Reference in New Issue
Block a user