Skip to content

Commit

Permalink
Hotfix: 스와이프 코치마크의 백드랍을 클릭하여도 모달이 닫히지 않도록 수정 (#447)
Browse files Browse the repository at this point in the history
* feat: canCloseByBackDrop 속성을 추가하여 backdrop 클릭으로 모달닫기 여부 적용

* fix: 스와이프 코치마크 모달은 백드랍 클릭시 닫히지 않도록 수정
  • Loading branch information
cruelladevil authored Sep 21, 2023
1 parent d371aa3 commit cdf46ea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
7 changes: 6 additions & 1 deletion frontend/src/pages/SongDetailListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,12 @@ const SongDetailListPage = () => {
return (
<>
{onboarding && (
<Modal isOpen={isOpen} closeModal={closeCoachMark} css={{ backgroundColor: 'transparent' }}>
<Modal
isOpen={isOpen}
closeModal={closeCoachMark}
css={{ backgroundColor: 'transparent' }}
canCloseByBackDrop={false}
>
<Spacing direction="vertical" size={170} />
<img src={swipeUpDown} width="100px" />
<Spacing direction="vertical" size={30} />
Expand Down
17 changes: 15 additions & 2 deletions frontend/src/shared/components/Modal/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@ interface ModalProps extends HTMLAttributes<HTMLDivElement> {
closeModal: () => void;
children: ReactElement | ReactElement[];
css?: CSSProp;
canCloseByBackDrop?: boolean;
}

const Modal = ({ isOpen, closeModal, children, css }: PropsWithChildren<ModalProps>) => {
const Modal = ({
canCloseByBackDrop = true,
isOpen,
closeModal,
children,
css,
}: PropsWithChildren<ModalProps>) => {
const closeByEsc = useCallback(
({ key }: KeyboardEvent) => {
if (key === 'Escape') {
Expand All @@ -21,6 +28,12 @@ const Modal = ({ isOpen, closeModal, children, css }: PropsWithChildren<ModalPro
[closeModal]
);

const closeModalByBackDrop = () => {
if (!canCloseByBackDrop) return;

closeModal();
};

useEffect(() => {
if (isOpen) {
document.body.style.overflow = 'hidden';
Expand All @@ -37,7 +50,7 @@ const Modal = ({ isOpen, closeModal, children, css }: PropsWithChildren<ModalPro
<>
{isOpen && (
<Wrapper>
<Backdrop role="backdrop" onClick={closeModal} aria-hidden="true" />
<Backdrop role="backdrop" onClick={closeModalByBackDrop} aria-hidden="true" />
<Container role="dialog" $css={css}>
{children}
</Container>
Expand Down

0 comments on commit cdf46ea

Please sign in to comment.