Skip to content

Commit

Permalink
ダイアログの外側をクリックして閉じる
Browse files Browse the repository at this point in the history
  • Loading branch information
narumincho committed Jul 7, 2024
1 parent 2f7816f commit 0cb8e3d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions client/SignUpDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,17 @@ export const SignUpDialog = (props: {

useEffect(() => {
ref.current?.addEventListener("close", props.onClose);
const clickHandler = (event: MouseEvent) => {
if (event.target instanceof HTMLElement) {
if (event.target.closest("form") === null) {
props.onClose();
}
}
};
ref.current?.addEventListener("click", clickHandler);
return () => {
ref.current?.removeEventListener("close", props.onClose);
ref.current?.removeEventListener("click", clickHandler);
};
}, [props.onClose, ref.current]);

Expand Down
Loading

0 comments on commit 0cb8e3d

Please sign in to comment.