Skip to content

Commit a198525

Browse files
committed
feat: 홈이동 모달에 useOutsideClick훅 연결
1 parent a9734f0 commit a198525

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/components/HomeNavigateConfirmModal/HomeNavigateConfirmModal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const HomeNavigateConfirmModal = ({ isOpen, handleClose }: HomeNavigateConfirmMo
4242
};
4343

4444
return (
45-
<Modal isOpen={isOpen}>
45+
<Modal isOpen={isOpen} onClose={handleClose}>
4646
<div className={styles.Modal}>
4747
<Text variant="titleSm" color="primary" align="center" as="h2">
4848
홈으로 가시겠어요?

src/components/ui/Modal/Modal.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
import type { PropsWithChildren } from "react";
2-
import { useEffect } from "react";
2+
import { useEffect, useRef } from "react";
33

44
import classNames from "classnames";
55

66
import styles from "@/components/ui/Modal/Modal.module.scss";
77
import Portal from "@/components/ui/Modal/Portal";
88

9+
import useClickOutside from "@/hooks/common/useClickOutside";
10+
911
interface ModalProps extends PropsWithChildren {
12+
onClose: () => void;
1013
isOpen: boolean;
1114
}
1215

13-
const Modal = ({ isOpen, children }: ModalProps) => {
16+
const Modal = ({ isOpen, children, onClose }: ModalProps) => {
1417
useEffect(() => {
1518
document.body.style.overflow = "hidden";
1619

@@ -19,6 +22,10 @@ const Modal = ({ isOpen, children }: ModalProps) => {
1922
};
2023
}, []);
2124

25+
const modalRef = useRef<HTMLDivElement>(null);
26+
27+
useClickOutside(modalRef, onClose);
28+
2229
return (
2330
<>
2431
{isOpen && (
@@ -30,6 +37,7 @@ const Modal = ({ isOpen, children }: ModalProps) => {
3037
/>
3138

3239
<div
40+
ref={modalRef}
3341
className={classNames(styles.Modal, {
3442
[styles.Open]: isOpen,
3543
})}

0 commit comments

Comments
 (0)