mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
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>
42 lines
1017 B
TypeScript
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>
|
|
);
|
|
}
|