Skip to content

Commit e451323

Browse files
committed
fix: 모달 컴포넌트 버그 수정
1 parent 3f1c4ae commit e451323

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/components/Modal/AlertModalLayout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ export default function AlertModalLayout({
4242
`}
4343
onClick={(e) => e.stopPropagation()}
4444
>
45-
{Icon && <Icon className="w-6 h-6 mb-6 mx-auto" />}{" "}
45+
{Icon && <Icon className="w-6 h-6 mb-6 mx-auto shrink-0" />}{" "}
4646
<p className="text-gray-900 text-base md:text-lg mb-[1rem]">{message}</p>
4747
<div
4848
className={
4949
type === "message"
50-
? "absolute bottom-6 right-6 md:right-6 md:bottom-6 mx-auto md:mx-0"
50+
? "w-full absolute bottom-6 flex justify-center sm:justify-end sm:right-6 sm:bottom-6"
5151
: ""
5252
}
5353
>

src/components/Modal/Modal.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { useEffect } from "react";
2+
13
import AlertModalLayout from "./AlertModalLayout";
24
import ConfirmModalLayout from "./ConfirmModalLayout";
35

@@ -6,6 +8,28 @@ import { useModalStore } from "@/store/useModalStore";
68
export default function Modal() {
79
const { isOpen, options, closeModal } = useModalStore();
810

11+
useEffect(() => {
12+
if (!isOpen) return;
13+
14+
const handleKeyDown = (e: KeyboardEvent) => {
15+
if (e.key === "Enter") {
16+
e.preventDefault(); // 🔥 기본 엔터 동작 차단 (버튼 재실행 방지)
17+
e.stopPropagation(); // 이벤트 버블링도 막기
18+
if (options?.type === "confirm") {
19+
options.onConfirm?.();
20+
}
21+
if (document.activeElement instanceof HTMLElement) {
22+
document.activeElement.blur();
23+
}
24+
25+
closeModal();
26+
}
27+
};
28+
29+
window.addEventListener("keydown", handleKeyDown);
30+
return () => window.removeEventListener("keydown", handleKeyDown);
31+
}, [isOpen, options, closeModal]);
32+
933
if (!isOpen || !options) return null;
1034

1135
const handleClose = () => {

0 commit comments

Comments
 (0)