Skip to content

Dialog Primitive

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

Installation

Install the component via your command line.

Terminal window
npx expo install @rn-primitives/dialog

Usage

import * as DialogPrimitive from '@rn-primitives/dialog';
import { Text } from 'react-native';
function Example() {
return (
<DialogPrimitive.Root>
<DialogPrimitive.Trigger>
<Text>Show Dialog</Text>
</DialogPrimitive.Trigger>
<DialogPrimitive.Portal>
<DialogPrimitive.Overlay>
<DialogPrimitive.Content>
<DialogPrimitive.Title>Dialog Title</DialogPrimitive.Title>
<DialogPrimitive.Description>
Dialog description.
</DialogPrimitive.Description>
<DialogPrimitive.Close><Text>Close</Text></DialogPrimitive.Close>
</DialogPrimitive.Content>
</DialogPrimitive.Overlay>
</DialogPrimitive.Portal>
</DialogPrimitive.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 Pressable props

PropTypeNote
asChildboolean(optional)
forceMounttrue | undefined;(optional)
closeOnPressboolean(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)
onInteractOutside(ev: Event) => voidWeb Only (optional)
onPointerDownOutside(ev: Event) => voidWeb Only (optional)

Title

Extends Text props

PropTypeNote
asChildboolean(optional)

Description

Extends Text props

PropTypeNote
asChildboolean(optional)

Close

Extends Pressable props

PropTypeNote
asChildboolean(optional)

useRootContext

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