Skip to content

Alert Dialog Primitive

Types Primitives Hooks Primitives Slot Primitives Portal Primitives

@radix-ui/react-alert-dialog


A modal dialog that interrupts the user with important content and expects a response.

Installation

Install @radix-ui/react-alert-dialog

Terminal window
npx expo install @radix-ui/react-alert-dialog

Copy/paste the following code for web to ~/components/primitives/alert-dialog/alert-dialog.web.tsx

Copy/paste the following code for native to ~/components/primitives/alert-dialog/alert-dialog.tsx

Copy/paste the following code for types to ~/components/primitives/alert-dialog/types.ts

Copy/paste the following code for exporting to ~/components/primitives/alert-dialog/index.ts

Usage

import * as AlertDialogPrimitive from '~/components/primitives/alert-dialog';
import { Text } from 'react-native';
function Example() {
return (
<AlertDialogPrimitive.Root>
<AlertDialogPrimitive.Trigger>
<Text>Show Alert Dialog</Text>
</AlertDialogPrimitive.Trigger>
<AlertDialogPrimitive.Portal>
<AlertDialogPrimitive.Overlay>
<AlertDialogPrimitive.Content>
<AlertDialogPrimitive.Title>Are you absolutely sure?</AlertDialogPrimitive.Title>
<AlertDialogPrimitive.Description>
This action cannot be undone. This will permanently delete your account and remove your data from our servers.
</AlertDialogPrimitive.Description>
<AlertDialogPrimitive.Cancel><Text>Cancel</Text></AlertDialogPrimitive.Cancel>
<AlertDialogPrimitive.Action><Text>Continue</Text></AlertDialogPrimitive.Action>
</AlertDialogPrimitive.Content>
</AlertDialogPrimitive.Overlay>
</AlertDialogPrimitive.Portal>
</AlertDialogPrimitive.Root>
);
}

Props

Root

Extends View props

PropTypeNote
asChildboolean(optional)
openboolean(optional)
onOpenChange(value: boolean) => void(optional)
defaultOpenboolean(optional)

Trigger

Extends Pressable props

PropTypeNote
asChildboolean(optional)

Overlay

Extends View props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined;(optional)

Portal

PropTypeNote
children*React.ReactNode
forceMounttrue | undefined(optional)
hostNamestringWeb Only (optional)
containerHTMLElement | null | undefinedWeb Only (optional)

Content

Extends View props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined(optional)
alignOffsetnumberNative Only (optional)
insetsInsetsNative Only (optional)
avoidCollisionsbooleanNative Only (optional)
align’start’ | ‘center’ | ‘end’Native Only (optional)
side’top’ | ‘bottom’Native Only (optional)
sideOffsetnumberNative Only (optional)
disablePositioningStylebooleanNative Only (optional)
onOpenAutoFocus(ev: Event) => voidWeb Only (optional)
onCloseAutoFocus(ev: Event) => voidWeb Only (optional)
onEscapeKeyDown(ev: Event) => voidWeb Only (optional)

Title

Extends Text props

PropTypeNote
asChildboolean(optional)

Description

Extends Text props

PropTypeNote
asChildboolean(optional)

Cancel

Extends Pressable props

PropTypeNote
asChildboolean(optional)

Action

Extends Pressable props

PropTypeNote
asChildboolean(optional)

useRootContext

Must be used within a Root component. It provides the following values from the alert-dialog: open, and onOpenChange.