Skip to Content

Built by moveinready.casa  and the community

Shadcn Docs

Radix Docs

Dialog

A window overlaid on either the primary window or another dialog window, rendering the content underneath inert.

Usage

import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; <Dialog> <DialogTrigger asChild> <Button>Open dialog</Button> </DialogTrigger> <DialogPortal> <DialogOverlay /> <DialogContent> <DialogHeader> <DialogTitle>Share link</DialogTitle> <DialogDescription> Copy the link below to share this document. </DialogDescription> </DialogHeader> <View className="bg-muted my-4 rounded p-3"> <Text selectable>https://example.com/very/long/link</Text> </View> <DialogFooter> <DialogClose asChild> <Button>Copy</Button> </DialogClose> </DialogFooter> </DialogContent> </DialogPortal> </Dialog>;

Components

Dialog

PropTypeDefaultDescription
modalbooleantrueWhether the dialog is modal (prevents interaction with elements outside the dialog).
defaultOpenbooleanfalseUncontrolled default open state of the dialog.
openboolean-Controlled open state of the dialog.
onOpenChange(isOpen: boolean) => void-Callback function called when the dialog open state changes.
forceMountbooleanfalseWhether to force mount the dialog content even when closed.
asChildbooleanfalseIf true clones the child and passes all accessibility and functionality props to it.
baseClassNamestring-Custom tailwind classes to apply to the base dialog component. Takes priority over the className prop.

Also extends all React Native View component props.

DialogTrigger

PropTypeDefaultDescription
disabledbooleanfalseWhether the dialog trigger is disabled.
asChildbooleanfalseIf true clones the child and passes all accessibility and functionality props to it. Available on any exported component.
baseClassNamestring-Custom tailwind classes to apply to the base dialog trigger component. Takes priority over the className prop.

Also extends all React Native Pressable component props.

DialogContent

PropTypeDefaultDescription
modalbooleantrueWhether the dialog is modal (prevents interaction with elements outside the dialog).
borderRadius"none" | "sm" | "md" | "lg" | "xl""lg"Sets the border radius of the dialog content.
forceMountbooleanfalseWhether to force mount the dialog content even when closed.
onOpenAutoFocus(e: React.FocusEvent) => void-Callback function called when the dialog opens and auto-focus is triggered.
onCloseAutoFocus(e: React.FocusEvent) => void-Callback function called when the dialog closes and auto-focus is triggered.
onEscapeKeyDown(e: React.KeyboardEvent) => void-Callback function called when the Escape key is pressed.
onPointerDownOutside(e: GestureResponderEvent | React.FocusEvent) => void-Callback function called when a pointer event occurs outside the dialog.
onInteractOutside(e: GestureResponderEvent | React.FocusEvent) => void-Callback function called when an interaction occurs outside the dialog.
asChildbooleanfalseIf true clones the child and passes all accessibility and functionality props to it.
classNamestring-Custom tailwind classes to apply to the dialog content component.
baseClassNamestring-Custom tailwind classes to apply to the base dialog content component. Takes priority over the className prop.

Also extends all React Native View component props.

DialogHeader

PropTypeDefaultDescription
baseClassNamestring-Custom tailwind classes to apply to the base dialog header component. Takes priority over the className prop.

Also extends all React Native View component props.

DialogFooter

PropTypeDefaultDescription
baseClassNamestring-Custom tailwind classes to apply to the base dialog footer component. Takes priority over the className prop.

Also extends all React Native View component props.

DialogTitle

PropTypeDefaultDescription
asChildbooleanfalseIf true clones the child and passes all accessibility and functionality props to it. Available on any exported component.
baseClassNamestring-Custom tailwind classes to apply to the base dialog title component. Takes priority over the className prop.

Also extends all React Native Text component props.

DialogDescription

PropTypeDefaultDescription
asChildbooleanfalseIf true clones the child and passes all accessibility and functionality props to it. Available on any exported component.
baseClassNamestring-Custom tailwind classes to apply to the base dialog description component. Takes priority over the className prop.

Also extends all React Native Text component props.

DialogClose

PropTypeDefaultDescription
asChildbooleanfalseIf true clones the child and passes all accessibility and functionality props to it. Available on any exported component.
baseClassNamestring-Custom tailwind classes to apply to the base dialog close component. Takes priority over the className prop.

Also extends all React Native Pressable component props.

DialogPortal

Note: The DialogPortal is not used in this library as there is no body element in React Native, it is only here for compatibility with the Radix UI and Shadcn UI and can be removed if not used.

Extends all React Native View component props.

DialogOverlay

PropTypeDefaultDescription
asChildbooleanfalseIf true clones the child and passes all accessibility and functionality props to it. Available on any exported component.
baseClassNamestring-Custom tailwind classes to apply to the base dialog overlay component. Takes priority over the className prop.

Also extends all React Native View component props.

Hooks

useDialog

The backbone hook for the dialog component that manages state and provides accessibility props.

Parameters:

ParameterTypeDefaultDescription
defaultOpenbooleanfalseUncontrolled default open state of the dialog.
openboolean-Controlled open state of the dialog.
onOpenChange(isOpen: boolean) => void-Callback function called when the dialog open state changes.
forceMountbooleanfalseWhether to force mount the dialog content even when closed.

Returns:

{ state: { isOpen: boolean; setIsOpen: (isOpen: boolean) => void; }; overlayProps: ComponentProps<typeof TouchableWithoutFeedback>; }
PropertyTypeDescription
state.isOpenbooleanWhether the dialog is open.
state.setIsOpen(isOpen: boolean) => voidFunction to set the open state of the dialog.
overlayPropsComponentProps<typeof TouchableWithoutFeedback>Props to pass to the dialog overlay component.

useDialogTrigger

The hook for the dialog trigger component that provides accessibility props.

Parameters:

ParameterTypeDefaultDescription
stateDialogReturn-Required. The dialog state from useDialog.
disabledbooleanfalseWhether the dialog trigger is disabled.

Returns:

{ componentProps: ComponentProps<typeof View> | HTMLButtonElement; }
PropertyTypeDescription
componentPropsComponentProps<typeof View> | HTMLButtonElementAccessibility props to pass to the dialog trigger component.

useDialogContent

The hook for the dialog content component that provides accessibility props.

Parameters:

ParameterTypeDefaultDescription
modalbooleantrueWhether the dialog is modal.
stateDialogReturn-Required. The dialog state from useDialog.
forceMountbooleanfalseWhether to force mount the dialog content.
onOpenAutoFocus(e: React.FocusEvent) => void-Callback when dialog opens and auto-focus is triggered.
onCloseAutoFocus(e: React.FocusEvent) => void-Callback when dialog closes and auto-focus is triggered.
onEscapeKeyDown(e: React.KeyboardEvent) => void-Callback when Escape key is pressed.
onPointerDownOutside(e: GestureResponderEvent | React.FocusEvent) => void-Callback when pointer event occurs outside dialog.
onInteractOutside(e: GestureResponderEvent | React.FocusEvent) => void-Callback when interaction occurs outside dialog.

Returns:

{ componentProps: ComponentProps<typeof View> | HTMLDivElement; titleProps: ComponentProps<typeof View> | HTMLDivElement; closeButtonProps: ComponentProps<typeof View> | HTMLDivElement; }
PropertyTypeDescription
componentPropsComponentProps<typeof View> | HTMLDivElementAccessibility props to pass to the dialog content component.
titlePropsComponentProps<typeof View> | HTMLDivElementAccessibility props to pass to the dialog title component.
closeButtonPropsComponentProps<typeof View> | HTMLDivElementAccessibility props to pass to the dialog close button component.

Accessibility

The Dialog component is built with accessibility in mind and includes:

Web Accessibility

  • Uses useDialog hook for proper dialog semantics
  • Uses useButton hook for proper button semantics on trigger and close buttons
  • Uses useFocusRing for focus management
  • Supports ARIA attributes: role="dialog", aria-modal="true", aria-labelledby, aria-describedby
  • Keyboard navigation support (Escape to close, Tab for focus management)
  • Focus trap within dialog content

React Native Accessibility

  • accessibilityRole="dialog" for proper screen reader announcement
  • accessibilityLiveRegion="polite" for dynamic content updates
  • accessibilityViewIsModal for modal behavior
  • accessibilityLabel and accessibilityHint on trigger and close buttons
  • Proper focus management for screen readers

Styling

Dialog Classes

Slots:

  • base - For the base View in the dialog component
  • overlay - For the overlay container
  • content - For the main content container
  • closeButton - For the close button
  • closeIcon - For the close button icon

Variants:

  • borderRadius:
    • none - No radius: rounded-none
    • sm - Small radius: rounded-sm
    • md - Medium radius: rounded-md
    • lg (default) - Large radius: rounded-lg
    • xl - Extra large radius: rounded-xl

Base Classes:

  • overlay: fixed inset-0 z-50 bg-black opacity-80
  • content: fixed left-[50%] top-[50%] z-50 w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border border-border bg-background p-6 shadow-lg rounded-lg
  • closeButton: absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity text-muted-foreground hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none

DialogHeader Classes

Base Classes: flex justify-center sm:justify-start w-full

DialogFooter Classes

Base Classes: flex flex-col-reverse gap-2 sm:flex-row sm:justify-end

DialogTitle Classes

Base Classes: text-lg font-semibold leading-none tracking-tight text-foreground

DialogDescription Classes

Base Classes: text-sm text-muted-foreground

shadcn-native

Built by moveinready.casa and the community