Skip to content

Commit

Permalink
Merge pull request #595 from openameba/fix/appeal-modal
Browse files Browse the repository at this point in the history
fix(spindle-ui): remove closing className
  • Loading branch information
lanberb committed Dec 16, 2022
2 parents b7adcba + 3101474 commit 3949ad5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/spindle-ui/src/Dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,23 @@ const Frame = forwardRef<DialogHTMLElement, DialogProps>(function Dialog(
typeof onClose === 'function' && onClose(event);
};

const handleDialogClick = (event: React.MouseEvent<DialogHTMLElement>) => {
// Detect backdrop click
if (event.target === dialogEl.current) {
onClose && onClose(event);
}
};

const handleDialogClose = (
event: React.SyntheticEvent<DialogHTMLElement>,
) => {
// Detect escape key type
if (event.target === dialogEl.current) {
onClose && onClose(event);
setClosing(false);
}
};

const handleAnimationEnd = useCallback(
(event: AnimationEvent) => {
if (
Expand Down Expand Up @@ -91,6 +108,8 @@ const Frame = forwardRef<DialogHTMLElement, DialogProps>(function Dialog(
.filter(Boolean)
.join(' ')
.trim()}
onClick={handleDialogClick}
onClose={handleDialogClose}
{...rest}
>
<form method="dialog" onSubmit={handleFormSubmit}>
Expand Down
12 changes: 11 additions & 1 deletion packages/spindle-ui/src/Modal/AppealModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ const Frame = forwardRef<DialogHTMLElement, AppealModalProps>(
}
};

const handleDialogClose = (
event: React.SyntheticEvent<DialogHTMLElement>,
) => {
// Detect escape key type
if (event.target === dialogEl.current) {
onClose && onClose(event);
setClosing(false);
}
};

const handleAnimationEnd = useCallback(
(event: AnimationEvent) => {
if (
Expand All @@ -57,7 +67,6 @@ const Frame = forwardRef<DialogHTMLElement, AppealModalProps>(
!event.pseudoElement // To exclude ::backdrop
) {
dialogEl.current.close && dialogEl.current.close();
setClosing(false);
}
},
[dialogEl],
Expand Down Expand Up @@ -107,6 +116,7 @@ const Frame = forwardRef<DialogHTMLElement, AppealModalProps>(
.trim()}
ref={mergeRefs([dialogEl, ref])}
onClick={handleDialogClick}
onClose={handleDialogClose}
{...rest}
>
<form
Expand Down

0 comments on commit 3949ad5

Please sign in to comment.