React Native / Overlays
Dialog
Centered modal dialog. Screen readers stay inside it while it's open, and the title is read first.
import { Dialog } from "@stylhero/native";
Example
import { useState } from "react";
import { Button, Dialog, Text } from "@stylhero/native";
function DialogExample() {
const [open, setOpen] = useState(false);
return (
<>
<Button variant="danger" onPress={() => setOpen(true)}>Delete build</Button>
<Dialog
visible={open}
onClose={() => setOpen(false)}
title="Delete this build?"
actions={
<>
<Button variant="secondary" onPress={() => setOpen(false)}>Cancel</Button>
<Button variant="danger" onPress={() => setOpen(false)}>Delete</Button>
</>
}
>
<Text>Its price alerts are deleted too.</Text>
</Dialog>
</>
);
}
Props
| Prop | Type | Default | Description |
|---|---|---|---|
onClose required |
() => void |
- | Called on the backdrop, Android back, and the iOS escape gesture (unless dismissable is false). |
title required |
string |
- | |
visible required |
boolean |
- | |
actions |
ReactNode |
- | Buttons at the bottom, e.g. Cancel and Delete. They wrap onto their own rows when space is short. |
children |
ReactNode |
- | Body. A string is styled for you. |
dismissable |
boolean |
true |
Set to false for a decision the user must make; then only the actions close it. |
testID |
string |
- |
Accessibility
- Screen readers stay inside it while it's open. Android back and the iOS escape gesture (two-finger Z) close it unless
dismissable={false}. - Use
dismissable={false}for decisions the user has to make.
Generated from src/components/Dialog.tsx. Something wrong or missing? Open an issue.