Overlays
AlertDialog
Asks before something that cannot be undone. Focus starts on Cancel. returnFocusTo names the element that gets the focus when the dialog closes, for example a section heading after a link in the dialog moved the person there. Without it, the focus goes back to the element that had the focus when the dialog opened. It works only without trigger. The element must take the focus (a heading needs tabIndex={-1}).
import { AlertDialog } from "@percentsa/ui";Examples
Code
export function AlertDialogExample() {
const t = useT();
return (
<AlertDialog
trigger={<Button variant="danger">{t("Delete project", "حذف المشروع")}</Button>}
title={t("Delete this project?", "حذف هذا المشروع؟")}
description={t("Files and history are removed. This cannot be undone.", "تُحذف الملفات والسجل. لا يمكن التراجع.")}
action={t("Delete", "حذف")}
destructive
// A Promise keeps the dialog open, with a loading button, until it resolves.
onAction={async () => {
await new Promise((done) => setTimeout(done, 1200));
toast({ title: t("Project deleted", "حُذف المشروع") });
}}
/>
);
}