Instalación
npx logic2b@next add alert-dialogUso
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog"
<AlertDialog>
<AlertDialogTrigger>Eliminar cuenta</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>¿Confirmas la acción?</AlertDialogTitle>
<AlertDialogDescription>
Esta acción no se puede deshacer.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancelar</AlertDialogCancel>
<AlertDialogAction>Continuar</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
Notas de uso
AlertDialogAction y AlertDialogCancel usan respectivamente las variantes de botón predeterminada y outline. Pasa className para cambiar su estilo, por ejemplo en una acción destructiva.
Ejemplos
Acción destructiva
Aplica la variante destructiva al botón de confirmación en operaciones irreversibles.
Controlado
Abre el diálogo desde tu propio estado con open y onOpenChange.
Accesibilidad
- Sigue el patrón WAI-ARIA de diálogo de alerta y mantiene el foco dentro mientras está abierto.
- Al abrirse mueve el foco al diálogo; al cerrarse lo devuelve al disparador.
- Escape cierra el diálogo y dispara
AlertDialogCancel. A diferencia de un diálogo normal, un clic en la capa exterior no lo cierra: es necesario responder. AlertDialogTitleetiqueta el contenido yAlertDialogDescriptionlo describe.
Playground interactivo
Edita las propiedades del componente y revisa el JSX exacto antes de copiarlo. La vista previa se carga solo cuando esta sección entra en pantalla.
<AlertDialog>
<AlertDialogTrigger
className="rounded-md border px-4 py-2 text-sm font-medium"
>Delete release</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete this release?</AlertDialogTitle>
<AlertDialogDescription>This action permanently removes the release artifacts.</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction>Delete</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>Referencia de API
Generada a partir de las exportaciones públicas de TypeScript en src/ui/alert-dialog.tsx. Las descripciones técnicas conservan el texto canónico del código fuente.
AlertDialog
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Root>AlertDialogPortal
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Portal>AlertDialogOverlay
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Overlay>AlertDialogTrigger
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Trigger>AlertDialogContent
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Content>AlertDialogHeader
ComponenteProps: React.ComponentProps<"div">AlertDialogFooter
ComponenteProps: React.ComponentProps<"div">AlertDialogTitle
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Title>AlertDialogDescription
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Description>AlertDialogAction
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Action>AlertDialogCancel
ComponenteProps: React.ComponentProps<typeof AlertDialogPrimitive.Cancel>Contrato de accesibilidad
Comportamiento legible por máquinas y responsabilidades de quien integra alert-dialog. Los detalles normativos conservan el texto canónico del registro.
- Soporte
- Gestionado por la primitiva
- Patrón
- alertdialog
- Radix Alert Dialog
| Teclas | Comportamiento |
|---|---|
| Escape | Close the open surface and restore focus. |
| Tab Shift+Tab | Move between confirmation actions. |
Semántica incorporada
- Uses alertdialog semantics, traps focus and requires an explicit action.
Responsabilidades de integración
- Describe the consequence and give destructive/escape actions unambiguous labels.