Close Modals on Escape

This commit is contained in:
Adam Shiervani 2025-10-13 17:09:10 +02:00
parent 5e06625966
commit e38b087ff6
1 changed files with 43 additions and 34 deletions

View File

@ -67,7 +67,15 @@ export function ConfirmDialog({
}: ConfirmDialogProps) {
const { icon: Icon, iconClass, iconBgClass, buttonTheme } = variantConfig[variant];
const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
if (e.key === "Escape") {
e.stopPropagation();
onClose();
}
};
return (
<div onKeyDown={handleKeyDown}>
<Modal open={open} onClose={onClose}>
<div className="mx-auto max-w-xl px-4 transition-all duration-300 ease-in-out">
<div className="pointer-events-auto relative w-full overflow-hidden rounded-lg bg-white p-6 text-left align-middle shadow-xl transition-all dark:bg-slate-800">
@ -108,5 +116,6 @@ export function ConfirmDialog({
</div>
</div>
</Modal>
</div>
);
}