Skip to content

Commit

Permalink
feat: 모달에 esc 버튼 클릭 시 닫는 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
dooohun committed Dec 1, 2024
1 parent 6d54411 commit 22dd871
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/client/src/shared/ui/modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ export default function Modal({ children, onClose }: ModalProps) {
const [isMounted, setIsMounted] = useState(false);
useEffect(() => {
setIsMounted(true);
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
onClose();
}
});
return () => {
document.removeEventListener('keydown', (e) => {
if (e.key === 'Escape') {
onClose();
}
});
};
}, []);
if (!isMounted) return null;
const handleBackdropClick = (e: React.MouseEvent<HTMLDivElement>) => {
Expand Down

0 comments on commit 22dd871

Please sign in to comment.