Skip to main content

Dialog

A dialog interrupts the user with an important prompt or a focused task. It follows the Material Design 3 Dialog specification.

Dialog renders through Portal, so wrap your app in a PortalHost once at the root. It claims the PORTAL_LAYERS.dialog layer, which puts it above bottom sheets and below snackbars, menus, and tooltips.

Usage​

import { Button, Dialog, PortalHost } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { useState } from 'react'
import { View } from 'react-native'

function Screen() {
const [open, setOpen] = useState(false)
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button onPress={() => setOpen(true)}>Delete file</Button>
<Dialog visible={open} onDismiss={() => setOpen(false)}>
<Dialog.Title>Delete file?</Dialog.Title>
<Dialog.Content>
This permanently removes report.pdf. You cannot undo this action.
</Dialog.Content>
<Dialog.Actions>
<Button variant="text" onPress={() => setOpen(false)}>Cancel</Button>
<Button variant="text" onPress={() => setOpen(false)}>Delete</Button>
</Dialog.Actions>
</Dialog>
</View>
)
}

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<PortalHost>
<Screen />
</PortalHost>
</ThemeProvider>
</SafeAreaProvider>
)
}

Slots​

Dialog composes from four slots. Write them in any order. Dialog places them in MD3 order (icon → headline → content → actions) itself. That is what lets the fullscreen variant move the title and the actions into its header. A slot can also sit in a fragment, so a conditional <>…</> of slots works.

SlotRendersMD3 role
Dialog.IconAn IconSource at 24dp, centeredOptional hero icon. Its presence centers the headline.
Dialog.TitleheadlineSmall / onSurfaceHeadline
Dialog.ContentStrings and numbers, also text with {expressions}, get bodyMedium / onSurfaceVariant. Anything else renders as isSupporting text or any content
Dialog.ActionsAn end-aligned row with an 8dp gapAction buttons: text Buttons per MD3

Dialog treats any other child as content, so <Dialog><MyForm /></Dialog> works with no extra setup.

The surface never grows past the screen. Content taller than the space left under the headline scrolls, and the headline and the actions stay in place, so the actions of a dismissable={false} dialog are always reachable.

With an icon​

An icon makes the dialog a hero dialog. The icon sits centered above the headline in secondary, and the headline centers with it.

import { Button, Dialog, PortalHost } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { useState } from 'react'
import { View } from 'react-native'

function Screen() {
const [open, setOpen] = useState(false)
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button variant="tonal" onPress={() => setOpen(true)}>Reset settings</Button>
<Dialog visible={open} onDismiss={() => setOpen(false)}>
<Dialog.Icon icon="alert-circle-outline" />
<Dialog.Title>Reset settings?</Dialog.Title>
<Dialog.Content>
Every preference returns to its default. Your data is untouched.
</Dialog.Content>
<Dialog.Actions>
<Button variant="text" onPress={() => setOpen(false)}>Cancel</Button>
<Button variant="text" onPress={() => setOpen(false)}>Reset</Button>
</Dialog.Actions>
</Dialog>
</View>
)
}

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<PortalHost>
<Screen />
</PortalHost>
</ThemeProvider>
</SafeAreaProvider>
)
}

Full-screen​

variant="fullscreen" fills the screen instead of a centered card. Dialog builds the MD3 header for you: a leading close button that calls onDismiss, the Dialog.Title as a titleLarge headline, and Dialog.Actions as the trailing confirming action. Dialog.Content scrolls below it. There is no scrim. The surface pads itself by the safe-area insets on every edge, so the header clears the status bar and the body clears the home indicator.

import { Button, Column, Dialog, PortalHost, TextField } from '@rootnative/components'
import { mdiResolver } from '@rootnative/components/mdi'
import { ThemeProvider } from '@rootnative/core'
import { SafeAreaProvider } from 'react-native-safe-area-context'
import { useState } from 'react'
import { View } from 'react-native'

function Screen() {
const [open, setOpen] = useState(false)
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button variant="tonal" onPress={() => setOpen(true)}>Edit profile</Button>
<Dialog visible={open} variant="fullscreen" onDismiss={() => setOpen(false)}>
<Dialog.Title>Edit profile</Dialog.Title>
<Dialog.Actions>
<Button variant="text" onPress={() => setOpen(false)}>Save</Button>
</Dialog.Actions>
<Dialog.Content>
<Column gap="lg">
<TextField label="Display name" value="Ada Lovelace" />
<TextField label="Email" value="ada@example.com" />
</Column>
</Dialog.Content>
</Dialog>
</View>
)
}

export default function App() {
return (
<SafeAreaProvider>
<ThemeProvider iconResolver={mdiResolver}>
<PortalHost>
<Screen />
</PortalHost>
</ThemeProvider>
</SafeAreaProvider>
)
}

Dismissal​

onDismiss fires for the ways out that the user starts: a scrim tap, the Android hardware back button, and the fullscreen close button. You wire the buttons inside Dialog.Actions yourself. Dialog never closes itself on an action press.

Set dismissable={false} when the user has to resolve the dialog with one of its actions. The scrim stops responding, assistive technology no longer announces it, and the back button falls through to navigation.

Motion​

A basic dialog scales up from 80% and fades in on springDefaultSpatial. The scrim fades on springFastEffects. The fullscreen variant rises 48dp instead of a scale.

Under reduced motion, each of these goes to its end value at once; see Motion.

Intentional deviation. MD3 slides a full-screen dialog up from the bottom edge of the screen. That needs the measured surface height, which fights the safe-area layout, so Root Native uses a 48dp rise. At spring speed the two look the same.

Tokens​

TokenBasicFull-screen
ContainersurfaceContainerHighsurface
Corner28dp (cornerExtraLarge)—
ElevationLevel 3—
Widthmin 280dp, max 560dpFills the screen
Padding24dp24dp body, 56dp header
Icon24dp, secondary24dp, secondary
HeadlineheadlineSmall / onSurfacetitleLarge / onSurface
Supporting textbodyMedium / onSurfaceVariantbodyMedium / onSurfaceVariant
ActionsText buttons, end-aligned, 8dp gapTrailing text button in the header
Scrimscrim @ 32%None

Accessibility​

  • Both surfaces report role="dialog" plus aria-modal and accessibilityViewIsModal, so assistive technology treats the content beneath as inert. Pass role="alertdialog" for a dialog that interrupts the user with something they must resolve. Assistive technology treats that role as urgent, so it is opt-in, not the default.
  • The dialog takes its accessible name from Dialog.Title when the headline is plain text, or text with {expressions} such as Delete {name}?. When you build the headline out of nodes, there is no text to take, so pass accessibilityLabel yourself.
  • Dialog.Title reports role="heading".
  • On the web, focus moves into the surface when it opens, Tab and Shift-Tab cycle inside it, Escape dismisses a dismissable dialog, and focus returns to the control that opened it on close. See Accessibility.
  • The scrim announces as a button labelled "Close dialog". Override it with scrimAccessibilityLabel. The scrim leaves the accessibility tree when dismissable={false}.
  • The fullscreen close button is labelled "Close". Override it with closeAccessibilityLabel.

Props​

PropTypeDefaultRequiredDescription
visibleboolean-YesWhether the dialog is shown. Exit animations run before it unmounts.
onDismiss() => void-YesCalled when the user dismisses the dialog — scrim tap, Android back button, or the fullscreen close button. Actions inside `Dialog.Actions` are wired up by the consumer, not by this callback.
childrenReactNode-No`Dialog.Icon`, `Dialog.Title`, `Dialog.Content`, `Dialog.Actions`.
variantenumbasicNoDialog anatomy.
dismissablebooleanNoWhether a scrim tap and the Android back button dismiss the dialog. Set `false` for a dialog the user must resolve with one of its actions.
containerColorstringsurfaceContainerHigh (basic) / surface (fullscreen)NoOverride the container (surface) color.
closeIconIconSource'close'NoIcon for the fullscreen variant's leading close button.
closeAccessibilityLabelstringCloseNoScreen-reader label for the fullscreen close button.
scrimAccessibilityLabelstringClose dialogNoScreen-reader label for the scrim's dismiss action.
roleViewProps'dialog'NoAnnounced role. An MD3 dialog is a plain `'dialog'`; pass `'alertdialog'` only for one that interrupts the user with something they must resolve (destructive confirmation, error), since assistive technology treats that role as urgent.
accessibilityLabelstring-NoAccessible name for the dialog. Derived from `Dialog.Title` when its headline is plain text, also text with `{expressions}`, so this is only needed when the headline is built from nodes or the dialog has no title.
styleStyleProp<ViewStyle>-NoStyle applied to the dialog surface.
scrimStyleStyleProp<ViewStyle>-NoStyle applied to the scrim. Ignored by the fullscreen variant.
testIDstring-NoTest id applied to the dialog surface.

Dialog.Icon​

PropTypeDefaultRequiredDescription
iconIconSource-YesIcon to display. Accepts a string name (resolved via the theme's `iconResolver`), a pre-rendered element, or a render function.
colorstringtheme.colors.secondaryNoOverride the icon color.
sizenumber24NoOverride the icon size in dp.
styleStyleProp<ViewStyle>-No-

Dialog.Title​

PropTypeDefaultRequiredDescription
childrenReactNode-YesHeadline text, or arbitrary nodes when a plain string isn't enough.
colorstringtheme.colors.onSurfaceNoOverride the headline color.
styleStyleProp<TextStyle>-No-

Dialog.Content​

PropTypeDefaultRequiredDescription
childrenReactNode-YesSupporting text or arbitrary content. Strings and numbers, also text with `{expressions}`, are wrapped in MD3 supporting-text styling. Anything else renders as given, so text beside an element needs its own `Text`.
colorstringtheme.colors.onSurfaceVariantNoOverride the supporting-text color.
styleStyleProp<ViewStyle>-No-

Dialog.Actions​

PropTypeDefaultRequiredDescription
childrenReactNode-YesAction buttons — text `Button`s per MD3.
styleStyleProp<ViewStyle>-No-