This merge updates a mobile fullscreen modal CSS selector assertion in the dashboard test suite, aligning it with a recent UI change to the modal structure. Fusion-Task-Id: FN-3374
67 lines
1.9 KiB
TypeScript
67 lines
1.9 KiB
TypeScript
import { useEffect, useRef } from "react";
|
|
import type { ConfirmOptions } from "../hooks/useConfirm";
|
|
import "./ConfirmDialog.css";
|
|
|
|
export interface ConfirmDialogProps {
|
|
isOpen: boolean;
|
|
options: ConfirmOptions | null;
|
|
onConfirm: () => void;
|
|
onCancel: () => void;
|
|
}
|
|
|
|
export function ConfirmDialog({ isOpen, options, onConfirm, onCancel }: ConfirmDialogProps) {
|
|
const cancelButtonRef = useRef<HTMLButtonElement | null>(null);
|
|
|
|
useEffect(() => {
|
|
if (!isOpen) {
|
|
return;
|
|
}
|
|
|
|
cancelButtonRef.current?.focus();
|
|
|
|
const onKeyDown = (event: KeyboardEvent) => {
|
|
if (event.key === "Escape") {
|
|
event.preventDefault();
|
|
onCancel();
|
|
}
|
|
};
|
|
|
|
document.addEventListener("keydown", onKeyDown);
|
|
return () => document.removeEventListener("keydown", onKeyDown);
|
|
}, [isOpen, onCancel]);
|
|
|
|
if (!isOpen || !options) {
|
|
return null;
|
|
}
|
|
|
|
return (
|
|
<div className="modal-overlay open confirm-dialog-overlay" onClick={onCancel}>
|
|
<div
|
|
className="modal confirm-dialog"
|
|
onClick={(event) => event.stopPropagation()}
|
|
role="dialog"
|
|
aria-modal="true"
|
|
aria-label={options.title}
|
|
>
|
|
<div className="modal-header">
|
|
<h3>{options.title}</h3>
|
|
<button className="modal-close" onClick={onCancel} aria-label="Close confirmation dialog">
|
|
×
|
|
</button>
|
|
</div>
|
|
|
|
<div className="confirm-dialog__body">{options.message}</div>
|
|
|
|
<div className="modal-actions confirm-dialog__actions">
|
|
<button ref={cancelButtonRef} className="btn" onClick={onCancel}>
|
|
{options.cancelLabel ?? "Cancel"}
|
|
</button>
|
|
<button className={`btn ${options.danger ? "btn-danger" : "btn-primary"}`} onClick={onConfirm}>
|
|
{options.confirmLabel ?? "Confirm"}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|