mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
feat(nav): peel overlays with esc, close the book on a second esc
This commit is contained in:
1 parent
2e15dc2dc9
commit
fe39274ed7
12 files changed
+130
-59
No files matched your search
@@ -1,4 +1,5 @@
|
||||
import { useEffect, useRef, type ReactNode } from "react";
|
||||
import { useEscapeLayer } from "../escape";
|
||||
import { Icon } from "./Icon";
|
||||
|
||||
interface ConfirmDialogProps {
|
||||
@@ -14,17 +15,10 @@ export function ConfirmDialog({ title, message, confirmLabel = "Delete", onConfi
|
||||
|
||||
useEffect(() => {
|
||||
confirmRef.current?.focus();
|
||||
const onKey = (e: KeyboardEvent) => {
|
||||
if (e.key === "Escape") {
|
||||
e.preventDefault();
|
||||
onClose();
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, []);
|
||||
|
||||
useEscapeLayer(true, onClose);
|
||||
|
||||
return (
|
||||
<div className="overlay" onClick={onClose}>
|
||||
<div className="panel panel-confirm" onClick={(e) => e.stopPropagation()}>
|
||||
|
||||
Reference in new issue
Block a user