feat: add Escape key handling to close modals and dialogs in App and UserProfile components

This commit is contained in:
Daniel Volz
2025-12-28 03:07:08 +01:00
parent f3da765f7c
commit 0ecb892a15
2 changed files with 20 additions and 1 deletions
+11
View File
@@ -499,6 +499,17 @@ export function UserProfile({ onClose }: { onClose?: () => void }) {
const [avatarLoading, setAvatarLoading] = useState(false);
const fileInputRef = useRef<HTMLInputElement>(null);
// Close on Escape key
useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === "Escape" && onClose) {
onClose();
}
};
document.addEventListener("keydown", handleEscape);
return () => document.removeEventListener("keydown", handleEscape);
}, [onClose]);
async function handleAvatarUpload(e: React.ChangeEvent<HTMLInputElement>) {
const file = e.target.files?.[0];
if (!file) return;