Fix: Remove padding on user profile.

Modals: Allow all modals to be closed by ESC (permitting).
Fix: Handle closing DMs properly. Stop propagation too.
This commit is contained in:
Paul
2021-06-24 16:57:12 +01:00
parent b724b9aec2
commit 2d9d3c489c
7 changed files with 27 additions and 22 deletions

View File

@@ -98,6 +98,7 @@ interface Props {
disallowClosing?: boolean;
noBackground?: boolean;
dontModal?: boolean;
padding?: boolean;
onClose: () => void;
actions?: Action[];
@@ -114,7 +115,7 @@ export default function Modal(props: Props) {
attachment={!!props.actions}
noBackground={props.noBackground}
border={props.border}
padding={!props.dontModal}>
padding={props.padding ?? !props.dontModal}>
{props.title && <h3>{props.title}</h3>}
{props.children}
</ModalContent>
@@ -124,6 +125,19 @@ export default function Modal(props: Props) {
return content;
}
useEffect(() => {
if (props.disallowClosing) return;
function keyDown(e: KeyboardEvent) {
if (e.key === "Escape") {
props.onClose();
}
}
document.body.addEventListener("keydown", keyDown);
return () => document.body.removeEventListener("keydown", keyDown);
}, [ props.disallowClosing, props.onClose ]);
let confirmationAction = props.actions?.find(action => action.confirmation);
useEffect(() => {
if (!confirmationAction) return;