Skip to content

Commit

Permalink
CloseablePopup: memo
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Feb 24, 2025
1 parent e90bcdf commit 4e1ad84
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/common/components/CloseablePopup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,22 @@ export function CloseablePopup(props: {
children?: React.ReactNode,
}) {

const handleClose = (event: MouseEvent | TouchEvent | React.KeyboardEvent) => {
const { onClose } = props;

const handleClose = React.useCallback((event: MouseEvent | TouchEvent | React.KeyboardEvent) => {
event.stopPropagation();
props.onClose();
};
onClose();
}, [onClose]);

const handleKeyDown = (event: React.KeyboardEvent) => {
const handleKeyDown = React.useCallback((event: React.KeyboardEvent) => {
if (event.key === 'Tab') {
handleClose(event);
} else if (event.key === 'Escape') {
if (props.anchorEl)
props.anchorEl?.focus();
handleClose(event);
}
};
}, [handleClose, props.anchorEl]);


// memos
Expand Down

0 comments on commit 4e1ad84

Please sign in to comment.