Skip to content

Commit

Permalink
fix: should be closed when press esc after click portal
Browse files Browse the repository at this point in the history
  • Loading branch information
linxianxi committed Aug 1, 2023
1 parent 3931701 commit 7a900f0
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/Operations.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Portal from '@rc-component/portal';
import classnames from 'classnames';
import CSSMotion from 'rc-motion';
import KeyCode from 'rc-util/lib/KeyCode';
import * as React from 'react';
import { useContext } from 'react';
import { PreviewGroupContext } from './context';
Expand Down Expand Up @@ -75,6 +76,22 @@ const Operations: React.FC<OperationsProps> = props => {
const { rotateLeft, rotateRight, zoomIn, zoomOut, close, left, right, flipX, flipY } = icons;
const toolClassName = `${prefixCls}-operations-operation`;

React.useEffect(() => {
const onKeyDown = (e: KeyboardEvent) => {
if (e.keyCode === KeyCode.ESC) {
onClose();
}
};

if (visible) {
window.addEventListener('keydown', onKeyDown);
}

return () => {
window.removeEventListener('keydown', onKeyDown);
};
}, [visible]);

const tools = [
{
icon: flipY,
Expand Down

0 comments on commit 7a900f0

Please sign in to comment.