인프런 커뮤니티 질문&답변
모달 UI 관련 질문
작성
·
65
0

이렇게 내용이 길어져서 모달 전체 크기인 max-h-[90vh]에 도달할 경우, 저는 모달 내부에 있는 버튼이 밖으로 안튀어나가게 작동할거라고 예상했는데, 첨부한 이미지처럼 튀어나가더라고요...이런 경우는 어떻게 해결할 수 있나요?
답변 1
0
이정환 Winterlood
지식공유자
안녕하세요 keenco님 이정환입니다.
이런 경우 모달내부 요소의 CSS 속성에 overflow-scroll 등을 추가해 스크롤바를 통해 해결할 수 있습니다. 강의에서도 아래에 보이시는 것 처럼 스크롤바를 통해 해결했으니 강의 코드를 참고해보셔도 좋을 것 같습니다 😀

keeenco
질문자
DialogContent와 textarea 여기저기 다 overflow-scroll을 추가해봤으나 해결되지 않는데 어디에 추가하신건지 자세히 알려주실 수 있을까요..?ㅠㅠ 제공해주신 코드와 diff checker까지 사용해봤으나 제가 다르게 입력한 부분을 못찾겠습니다..!!
(+ 같은 코드로 다른 모니터 환경에서는 강의처럼 정상 작동합니다. 노트북(권장사항인 120%배율)환경에서 이런거같은데, 잘못 작성된 코드가 아니라면 이런경우를 어떻게 대처하나요? 반응형으로 보완해줘야할까요? )
import { ImageIcon } from "lucide-react";
import { Button } from "../ui/button";
import { Dialog, DialogContent, DialogTitle } from "../ui/dialog";
import { usePostEditorModal } from "@/store/post-editor-modal";
import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { useCreatePost } from "@/hooks/mutations/post/use-create-post";
export default function PostEditorModal() {
const { isOpen, close } = usePostEditorModal();
const { mutate: createPost, isPending: isCreatePostPending } = useCreatePost({
onSuccess: () => {
close();
},
onError: (error) => {
toast.error("포스트 생성에 실패했습니다. 다시 시도해주세요.", {
position: "top-center",
});
},
});
const [content, setContent] = useState("");
const textareaRef = useRef<HTMLTextAreaElement>(null);
const handleCloseModal = () => {
close();
};
const handleCreatePostClick = () => {
if (content.trim() === "") return;
createPost(content);
};
useEffect(() => {
if (textareaRef.current) {
textareaRef.current.style.height = "auto";
textareaRef.current.style.height = `${textareaRef.current.scrollHeight}px`;
}
}, [content]);
useEffect(() => {
if (!isOpen) return;
textareaRef.current?.focus();
setContent("");
}, [isOpen]);
return (
<Dialog open={isOpen} onOpenChange={handleCloseModal}>
<DialogContent className="max-h-[90vh]">
<DialogTitle>포스트 작성</DialogTitle>
<textarea
disabled={isCreatePostPending}
ref={textareaRef}
value={content}
onChange={(e) => setContent(e.target.value)}
className="max-h-125 min-h-25 focus:outline-none"
placeholder="무슨 일이 있었나요?"
/>
<Button
disabled={isCreatePostPending}
variant="outline"
className="cursor-pointer"
>
<ImageIcon />
이미지 추가
</Button>
<Button
disabled={isCreatePostPending}
onClick={handleCreatePostClick}
className="cursor-pointer"
>
저장
</Button>
</DialogContent>
</Dialog>
);
}





감사합니다!!