Files
OpenHands/frontend/src/components/shared/modals/modal-backdrop.tsx
sp.wack cd2d0ee9a5 feat(frontend): Organizational support (#9496)
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: Hiep Le <69354317+hieptl@users.noreply.github.com>
Co-authored-by: Abhay Mishra <grabhaymishra@gmail.com>
Co-authored-by: Hyun Han <62870362+smosco@users.noreply.github.com>
Co-authored-by: Nhan Nguyen <nhan13574@gmail.com>
Co-authored-by: Bharath A V <avbharath1221@gmail.com>
Co-authored-by: hieptl <hieptl.developer@gmail.com>
Co-authored-by: Chloe <chloe@openhands.com>
Co-authored-by: HeyItsChloe <54480367+HeyItsChloe@users.noreply.github.com>
2026-03-13 23:38:54 +07:00

42 lines
1017 B
TypeScript

import React from "react";
interface ModalBackdropProps {
children: React.ReactNode;
onClose?: () => void;
"aria-label"?: string;
}
export function ModalBackdrop({
children,
onClose,
"aria-label": ariaLabel,
}: ModalBackdropProps) {
React.useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === "Escape") onClose?.();
};
window.addEventListener("keydown", handleEscape);
return () => window.removeEventListener("keydown", handleEscape);
}, []);
const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
if (e.target === e.currentTarget) onClose?.(); // only close if the click was on the backdrop
};
return (
<div
role="dialog"
aria-modal="true"
aria-label={ariaLabel}
className="fixed inset-0 flex items-center justify-center z-60"
>
<div
onClick={handleClick}
className="fixed inset-0 bg-black opacity-60"
/>
<div className="relative">{children}</div>
</div>
);
}