Skip to content

Commit

Permalink
fix: modals closing when trying to click interactive elements
Browse files Browse the repository at this point in the history
  • Loading branch information
Puyodead1 committed Aug 31, 2023
1 parent f983643 commit db94f52
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/components/modals/CreateServerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,11 @@ function CreateServerModal(props: AnimatedModalProps) {
});

return (
<Modal {...props}>
<Modal
{...props}
// used for clicking outside of the modal to close it
onClose={closeAllModals}
>
<ModalCloseWrapper>
<button
onClick={closeAllModals}
Expand Down
6 changes: 5 additions & 1 deletion src/components/modals/JoinServerModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,11 @@ function JoinServerModal(props: AnimatedModalProps) {
});

return (
<Modal {...props}>
<Modal
{...props}
// used for clicking outside of the modal to close it
onClose={closeAllModals}
>
<ModalCloseWrapper>
<button
onClick={closeAllModals}
Expand Down
10 changes: 8 additions & 2 deletions src/components/modals/ModalComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ interface ModalProps extends StackedModalProps {
children: React.ReactNode;
full?: boolean;
onClick?: () => void;
/**
* Custom callback for when a modal is closed by clicking the background overlay
*/
onClose?: () => void;
style?: React.CSSProperties;
}

Expand All @@ -196,8 +200,10 @@ export function Modal(props: ModalProps) {
initial="hide"
animate="show"
exit="hide"
onClick={() => {
closeModal();
onClick={(e) => {
if (e.target !== e.currentTarget) return;
if (props.onClose) props.onClose();
else closeModal();
}}
{...props}
>
Expand Down

0 comments on commit db94f52

Please sign in to comment.