diff --git a/docs/6.x/docs/components/Dialog/Dialog.mdx b/docs/6.x/docs/components/Dialog/Dialog.mdx
index e871f7f750..2a6a33f54d 100644
--- a/docs/6.x/docs/components/Dialog/Dialog.mdx
+++ b/docs/6.x/docs/components/Dialog/Dialog.mdx
@@ -21,7 +21,7 @@ To render the `Dialog` above other components, you'll need to wrap it with the [
```js
import * as React from 'react';
import { View } from 'react-native';
-import { Button, Dialog, Portal, PaperProvider, Text } from 'react-native-paper';
+import { Button, Dialog, Portal, PaperProvider } from 'react-native-paper';
const MyComponent = () => {
const [visible, setVisible] = React.useState(false);
@@ -35,15 +35,13 @@ const MyComponent = () => {
-
+
@@ -93,11 +91,75 @@ export default MyComponent;
diff --git a/docs/6.x/docs/components/Dialog/DialogActions.mdx b/docs/6.x/docs/components/Dialog/DialogActions.mdx
index b1d6bda29f..9f06c45722 100644
--- a/docs/6.x/docs/components/Dialog/DialogActions.mdx
+++ b/docs/6.x/docs/components/Dialog/DialogActions.mdx
@@ -28,12 +28,18 @@ const MyComponent = () => {
return (
-
+
);
};
diff --git a/docs/6.x/docs/components/Dialog/DialogContent.mdx b/docs/6.x/docs/components/Dialog/DialogContent.mdx
index 38771647f2..37b1d8dcc9 100644
--- a/docs/6.x/docs/components/Dialog/DialogContent.mdx
+++ b/docs/6.x/docs/components/Dialog/DialogContent.mdx
@@ -28,11 +28,7 @@ const MyComponent = () => {
return (
-
+
);
};
diff --git a/docs/6.x/docs/components/Dialog/DialogIcon.mdx b/docs/6.x/docs/components/Dialog/DialogIcon.mdx
index 34777210ca..226dc9aa22 100644
--- a/docs/6.x/docs/components/Dialog/DialogIcon.mdx
+++ b/docs/6.x/docs/components/Dialog/DialogIcon.mdx
@@ -20,7 +20,6 @@ A component to show an icon in a Dialog.
## Usage
```js
import * as React from 'react';
-import { StyleSheet } from 'react-native';
import { Dialog, Portal, Text } from 'react-native-paper';
const MyComponent = () => {
@@ -30,23 +29,11 @@ const MyComponent = () => {
return (
-
+
);
};
-const styles = StyleSheet.create({
- title: {
- textAlign: 'center',
- },
-})
-
export default MyComponent;
```
diff --git a/docs/6.x/docs/components/Dialog/DialogScrollArea.mdx b/docs/6.x/docs/components/Dialog/DialogScrollArea.mdx
index f5fc1904d2..15bc9e9afe 100644
--- a/docs/6.x/docs/components/Dialog/DialogScrollArea.mdx
+++ b/docs/6.x/docs/components/Dialog/DialogScrollArea.mdx
@@ -30,13 +30,7 @@ const MyComponent = () => {
return (
-
+
);
};
diff --git a/docs/6.x/docs/components/Dialog/DialogTitle.mdx b/docs/6.x/docs/components/Dialog/DialogTitle.mdx
index d548cffb85..df557bf5e6 100644
--- a/docs/6.x/docs/components/Dialog/DialogTitle.mdx
+++ b/docs/6.x/docs/components/Dialog/DialogTitle.mdx
@@ -28,12 +28,7 @@ const MyComponent = () => {
return (
-
+
);
};
diff --git a/docs/6.x/docs/components/Modal.mdx b/docs/6.x/docs/components/Modal.mdx
index 72691042b1..e7cd88fb58 100644
--- a/docs/6.x/docs/components/Modal.mdx
+++ b/docs/6.x/docs/components/Modal.mdx
@@ -87,6 +87,14 @@ export default MyComponent;
+### aria-label
+
+
+
+
+
+
+
### visible
diff --git a/docs/6.x/docs/guides/migration.md b/docs/6.x/docs/guides/migration.md
index 1fcd32bd25..48506a4b21 100644
--- a/docs/6.x/docs/guides/migration.md
+++ b/docs/6.x/docs/guides/migration.md
@@ -126,3 +126,55 @@ const theme = {
style={{ fontSize: 16, color: '#1C1B1F' }}
/>
```
+
+### Dialog
+
+The Paper 6.x `Dialog` now supports a simplified prop-based API for common dialog layouts. If your dialog previously composed `Dialog.Title`, `Dialog.Content`, and `Dialog.Actions` via `children`, migrate to the dedicated `icon`, `title`, `content`, and `actions` props.
+
+#### Removed props
+
+- **`children`** was removed from `Dialog`
+
+Use the dedicated props instead:
+
+- **`Dialog.Icon`** → **`icon`**
+- **`Dialog.Title`** → **`title`**
+- **`Dialog.Content`** → **`content`**
+- **`Dialog.Actions`** → **`actions`**
+
+The new **`actions`** prop is more customizable because it accepts **`React.ReactNode[]`**. Unlike the previous `Dialog.Actions` children behavior, the dialog no longer injects **`compact`** and **`uppercase`** into action components automatically. When **`actions`** is provided, the passed components are rendered through **`Dialog.Actions`** internally.
+
+#### New props
+
+- **`scrollable`** renders the dialog content inside a scrollable area.
+- **`contentProps`** passes props to the internal `Dialog.Content` when `scrollable` is not enabled.
+- **`scrollAreaProps`** passes props to the internal `Dialog.ScrollArea` when `scrollable` is enabled.
+- **`scrollViewProps`** passes props to the internal `ScrollView` when `scrollable` is enabled.
+- **`aria-label`** provides an accessibility label when the dialog title is not a string.
+
+```tsx
+// Before (v5)
+
+
+
+
+// After (v6)
+
+
+```
diff --git a/docs/src/data/componentDocs6x.json b/docs/src/data/componentDocs6x.json
index 300c315b99..fb37d05a76 100644
--- a/docs/src/data/componentDocs6x.json
+++ b/docs/src/data/componentDocs6x.json
@@ -5206,10 +5206,10 @@
"Dialog/Dialog": {
"filepath": "Dialog/Dialog.tsx",
"title": "Dialog",
- "description": "Dialogs inform users about a specific task and may contain critical information, require decisions, or involve multiple tasks.\nTo render the `Dialog` above other components, you'll need to wrap it with the [`Portal`](../Portal) component.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { View } from 'react-native';\nimport { Button, Dialog, Portal, PaperProvider, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const showDialog = () => setVisible(true);\n\n const hideDialog = () => setVisible(false);\n\n return (\n
\n \n \n \n \n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "Dialogs inform users about a specific task and may contain critical information, require decisions, or involve multiple tasks.\nTo render the `Dialog` above other components, you'll need to wrap it with the [`Portal`](../Portal) component.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { View } from 'react-native';\nimport { Button, Dialog, Portal, PaperProvider } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const showDialog = () => setVisible(true);\n\n const hideDialog = () => setVisible(false);\n\n return (\n
\n \n \n \n \n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"link": "dialog",
"data": {
- "description": "Dialogs inform users about a specific task and may contain critical information, require decisions, or involve multiple tasks.\nTo render the `Dialog` above other components, you'll need to wrap it with the [`Portal`](../Portal) component.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { View } from 'react-native';\nimport { Button, Dialog, Portal, PaperProvider, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const showDialog = () => setVisible(true);\n\n const hideDialog = () => setVisible(false);\n\n return (\n
\n \n \n \n \n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "Dialogs inform users about a specific task and may contain critical information, require decisions, or involve multiple tasks.\nTo render the `Dialog` above other components, you'll need to wrap it with the [`Portal`](../Portal) component.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { View } from 'react-native';\nimport { Button, Dialog, Portal, PaperProvider } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const showDialog = () => setVisible(true);\n\n const hideDialog = () => setVisible(false);\n\n return (\n
\n \n \n \n \n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"displayName": "Dialog",
"methods": [],
"statics": [],
@@ -5262,13 +5262,107 @@
"computed": false
}
},
- "children": {
- "required": true,
+ "icon": {
+ "required": false,
+ "tsType": {
+ "name": "IconSource"
+ },
+ "description": "Icon to display above the dialog title."
+ },
+ "title": {
+ "required": false,
"tsType": {
"name": "ReactReactNode",
"raw": "React.ReactNode"
},
- "description": "Content of the `Dialog`."
+ "description": "Title of the dialog."
+ },
+ "content": {
+ "required": false,
+ "tsType": {
+ "name": "ReactReactNode",
+ "raw": "React.ReactNode"
+ },
+ "description": "Content of the dialog. Non-empty strings are rendered as Material 3\nsupporting text."
+ },
+ "actions": {
+ "required": false,
+ "tsType": {
+ "name": "Array",
+ "elements": [
+ {
+ "name": "ReactReactNode",
+ "raw": "React.ReactNode"
+ }
+ ],
+ "raw": "React.ReactNode[]"
+ },
+ "description": "Action buttons displayed at the bottom of the dialog.\nKeep their order stable between renders."
+ },
+ "scrollable": {
+ "required": false,
+ "tsType": {
+ "name": "boolean"
+ },
+ "description": "Whether to render the content in a `ScrollView` within the dialog scroll\narea."
+ },
+ "contentProps": {
+ "required": false,
+ "tsType": {
+ "name": "Omit",
+ "elements": [
+ {
+ "name": "DialogContentProps"
+ },
+ {
+ "name": "literal",
+ "value": "'children'"
+ }
+ ],
+ "raw": "Omit
"
+ },
+ "description": "Props passed to `Dialog.Content` when `scrollable` is not enabled."
+ },
+ "scrollAreaProps": {
+ "required": false,
+ "tsType": {
+ "name": "Omit",
+ "elements": [
+ {
+ "name": "DialogScrollAreaProps"
+ },
+ {
+ "name": "literal",
+ "value": "'children'"
+ }
+ ],
+ "raw": "Omit"
+ },
+ "description": "Props passed to `Dialog.ScrollArea` when `scrollable` is enabled."
+ },
+ "scrollViewProps": {
+ "required": false,
+ "tsType": {
+ "name": "Omit",
+ "elements": [
+ {
+ "name": "ScrollViewProps"
+ },
+ {
+ "name": "literal",
+ "value": "'children'"
+ }
+ ],
+ "raw": "Omit"
+ },
+ "description": "Props passed to the `ScrollView` when `scrollable` is enabled."
+ },
+ "aria-label": {
+ "required": false,
+ "tsType": {
+ "name": "string"
+ },
+ "description": "Accessibility label for the dialog. This is read by the screen reader when the user opens a dialog."
},
"style": {
"required": false,
@@ -5313,10 +5407,10 @@
"Dialog/DialogActions": {
"filepath": "Dialog/DialogActions.tsx",
"title": "Dialog.Actions",
- "description": "A component to show a list of actions in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Button, Dialog, Portal } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show a list of actions in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Button, Dialog, Portal } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n );\n};\n\nexport default MyComponent;\n```",
"link": "dialog-actions",
"data": {
- "description": "A component to show a list of actions in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Button, Dialog, Portal } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show a list of actions in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Button, Dialog, Portal } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n );\n};\n\nexport default MyComponent;\n```",
"displayName": "Dialog.Actions",
"methods": [],
"statics": [],
@@ -5360,10 +5454,10 @@
"Dialog/DialogContent": {
"filepath": "Dialog/DialogContent.tsx",
"title": "Dialog.Content",
- "description": "A component to show content in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show content in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"link": "dialog-content",
"data": {
- "description": "A component to show content in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show content in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"displayName": "Dialog.Content",
"methods": [],
"statics": [],
@@ -5400,10 +5494,10 @@
"Dialog/DialogIcon": {
"filepath": "Dialog/DialogIcon.tsx",
"title": "Dialog.Icon",
- "description": "@supported Available in v5.x with theme version 3\nA component to show an icon in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { StyleSheet } from 'react-native';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nconst styles = StyleSheet.create({\n title: {\n textAlign: 'center',\n },\n})\n\nexport default MyComponent;\n```",
+ "description": "@supported Available in v5.x with theme version 3\nA component to show an icon in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"link": "dialog-icon",
"data": {
- "description": "@supported Available in v5.x with theme version 3\nA component to show an icon in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { StyleSheet } from 'react-native';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nconst styles = StyleSheet.create({\n title: {\n textAlign: 'center',\n },\n})\n\nexport default MyComponent;\n```",
+ "description": "@supported Available in v5.x with theme version 3\nA component to show an icon in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"displayName": "Dialog.Icon",
"methods": [],
"statics": [],
@@ -5451,10 +5545,10 @@
"Dialog/DialogScrollArea": {
"filepath": "Dialog/DialogScrollArea.tsx",
"title": "Dialog.ScrollArea",
- "description": "A component to show a scrollable content in a Dialog. The component only provides appropriate styling.\nFor the scrollable content you can use `ScrollView`, `FlatList` etc. depending on your requirement.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { ScrollView } from 'react-native';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show a scrollable content in a Dialog. The component only provides appropriate styling.\nFor the scrollable content you can use `ScrollView`, `FlatList` etc. depending on your requirement.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { ScrollView } from 'react-native';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"link": "dialog-scroll-area",
"data": {
- "description": "A component to show a scrollable content in a Dialog. The component only provides appropriate styling.\nFor the scrollable content you can use `ScrollView`, `FlatList` etc. depending on your requirement.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { ScrollView } from 'react-native';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show a scrollable content in a Dialog. The component only provides appropriate styling.\nFor the scrollable content you can use `ScrollView`, `FlatList` etc. depending on your requirement.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { ScrollView } from 'react-native';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"displayName": "Dialog.ScrollArea",
"methods": [],
"statics": [],
@@ -5498,10 +5592,10 @@
"Dialog/DialogTitle": {
"filepath": "Dialog/DialogTitle.tsx",
"title": "Dialog.Title",
- "description": "A component to show a title in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show a title in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"link": "dialog-title",
"data": {
- "description": "A component to show a title in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
+ "description": "A component to show a title in a Dialog.\n\n## Usage\n```js\nimport * as React from 'react';\nimport { Dialog, Portal, Text } from 'react-native-paper';\n\nconst MyComponent = () => {\n const [visible, setVisible] = React.useState(false);\n\n const hideDialog = () => setVisible(false);\n\n return (\n \n \n \n );\n};\n\nexport default MyComponent;\n```",
"displayName": "Dialog.Title",
"methods": [],
"statics": [],
@@ -9435,6 +9529,13 @@
"computed": false
}
},
+ "aria-label": {
+ "required": false,
+ "tsType": {
+ "name": "string"
+ },
+ "description": "Accessibility label for the dialog. This is read by the screen reader when the user opens a dialog."
+ },
"visible": {
"required": false,
"tsType": {
diff --git a/example/src/DrawerItems.tsx b/example/src/DrawerItems.tsx
index 94afa3136c..ced8ca108f 100644
--- a/example/src/DrawerItems.tsx
+++ b/example/src/DrawerItems.tsx
@@ -242,9 +242,11 @@ function DrawerItems() {
>
)}
-
+ }
+ actions={[
+ ,
+ ]}
+ />
);
diff --git a/example/src/Examples/DialogExample.tsx b/example/src/Examples/DialogExample.tsx
index d926ae6616..4628d5944d 100644
--- a/example/src/Examples/DialogExample.tsx
+++ b/example/src/Examples/DialogExample.tsx
@@ -103,10 +103,12 @@ const DialogExample = () => {
visible={_getVisible('dialog6')}
close={_toggleDialog('dialog6')}
/>
-
+ {Platform.OS === 'android' && (
+
+ )}
);
};
diff --git a/example/src/Examples/Dialogs/DialogTextComponent.tsx b/example/src/Examples/Dialogs/DialogTextComponent.tsx
deleted file mode 100644
index 9ad958f12e..0000000000
--- a/example/src/Examples/Dialogs/DialogTextComponent.tsx
+++ /dev/null
@@ -1,18 +0,0 @@
-import * as React from 'react';
-
-import { Text, Text as NativeText, useTheme } from 'react-native-paper';
-type Props = React.ComponentProps & {
- isSubheading?: boolean;
-};
-
-export const TextComponent = ({ isSubheading = false, ...props }: Props) => {
- const theme = useTheme();
-
- return (
-
- );
-};
diff --git a/example/src/Examples/Dialogs/DialogWithCustomColors.tsx b/example/src/Examples/Dialogs/DialogWithCustomColors.tsx
index f3625b835e..3eec815828 100644
--- a/example/src/Examples/Dialogs/DialogWithCustomColors.tsx
+++ b/example/src/Examples/Dialogs/DialogWithCustomColors.tsx
@@ -1,6 +1,6 @@
-import { Button, Portal, Dialog, Palette } from 'react-native-paper';
+import { StyleSheet } from 'react-native';
-import { TextComponent } from './DialogTextComponent';
+import { Button, Dialog, Palette, Portal, Text } from 'react-native-paper';
const DialogWithCustomColors = ({
visible,
@@ -8,30 +8,38 @@ const DialogWithCustomColors = ({
}: {
visible: boolean;
close: () => void;
-}) => {
- return (
-
-
- Alert
-
-
- This is a dialog with custom colors
-
-
-
-
-
-
-
- );
-};
+}) => (
+
+
+ Alert
+
+ }
+ content={
+
+ This is a dialog with custom colors
+
+ }
+ actions={[
+ ,
+ ]}
+ />
+
+);
+
+const styles = StyleSheet.create({
+ dialog: {
+ backgroundColor: Palette.primary10,
+ },
+ text: {
+ color: Palette.primary95,
+ },
+});
export default DialogWithCustomColors;
diff --git a/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx b/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx
index e9a7189068..fd7663dc79 100644
--- a/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx
+++ b/example/src/Examples/Dialogs/DialogWithDismissableBackButton.tsx
@@ -1,6 +1,4 @@
-import { Button, Portal, Dialog, Palette } from 'react-native-paper';
-
-import { TextComponent } from './DialogTextComponent';
+import { Button, Dialog, Palette, Portal } from 'react-native-paper';
const DialogWithDismissableBackButton = ({
visible,
@@ -15,21 +13,21 @@ const DialogWithDismissableBackButton = ({
visible={visible}
dismissable={false}
dismissableBackButton
- >
- Alert
-
-
- This is an undismissable dialog, however you can use hardware back
- button to close it!
-
-
-
-
-
+ ,
+
+ Agree
+ ,
+ ]}
+ />
);
diff --git a/example/src/Examples/Dialogs/DialogWithIcon.tsx b/example/src/Examples/Dialogs/DialogWithIcon.tsx
index 6281e9bf6c..c176946aa4 100644
--- a/example/src/Examples/Dialogs/DialogWithIcon.tsx
+++ b/example/src/Examples/Dialogs/DialogWithIcon.tsx
@@ -1,8 +1,4 @@
-import { StyleSheet } from 'react-native';
-
-import { Button, Portal, Dialog, Palette } from 'react-native-paper';
-
-import { TextComponent } from './DialogTextComponent';
+import { Button, Dialog, Palette, Portal } from 'react-native-paper';
const DialogWithIcon = ({
visible,
@@ -10,32 +6,24 @@ const DialogWithIcon = ({
}: {
visible: boolean;
close: () => void;
-}) => {
- return (
-
-
-
- Dialog with Icon
-
-
- This is a dialog with new component called DialogIcon. When icon is
- displayed you should center the header.
-
-
-
-
- Disagree
-
- Agree
-
-
-
- );
-};
+}) => (
+
+
+ Disagree
+ ,
+
+ Agree
+ ,
+ ]}
+ />
+
+);
-const styles = StyleSheet.create({
- title: {
- textAlign: 'center',
- },
-});
export default DialogWithIcon;
diff --git a/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx b/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx
index a28620e79c..892d24bed2 100644
--- a/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx
+++ b/example/src/Examples/Dialogs/DialogWithLoadingIndicator.tsx
@@ -1,8 +1,6 @@
import { ActivityIndicator, Platform, StyleSheet, View } from 'react-native';
-import { Dialog, Palette, Portal } from 'react-native-paper';
-
-import { TextComponent } from './DialogTextComponent';
+import { Dialog, Palette, Portal, Text, useTheme } from 'react-native-paper';
const isIOS = Platform.OS === 'ios';
@@ -13,31 +11,38 @@ const DialogWithLoadingIndicator = ({
visible: boolean;
close: () => void;
}) => {
+ const theme = useTheme();
+ const textColor = { color: theme.colors.onSurfaceVariant };
+
return (
-
- Progress Dialog
-
-
+
- Loading.....
+
+ Loading.....
+
-
-
+ }
+ />
);
};
const styles = StyleSheet.create({
- flexing: {
+ content: {
flexDirection: 'row',
alignItems: 'center',
},
- marginRight: {
+ indicator: {
marginRight: 16,
},
});
diff --git a/example/src/Examples/Dialogs/DialogWithLongText.tsx b/example/src/Examples/Dialogs/DialogWithLongText.tsx
index eeac1c7d3c..33a6c965d3 100644
--- a/example/src/Examples/Dialogs/DialogWithLongText.tsx
+++ b/example/src/Examples/Dialogs/DialogWithLongText.tsx
@@ -1,8 +1,6 @@
-import { Dimensions, ScrollView, StyleSheet } from 'react-native';
+import { Dimensions, StyleSheet } from 'react-native';
-import { Button, Portal, Dialog } from 'react-native-paper';
-
-import { TextComponent } from './DialogTextComponent';
+import { Portal, Dialog, Button } from 'react-native-paper';
const DialogWithLongText = ({
visible,
@@ -16,63 +14,27 @@ const DialogWithLongText = ({
onDismiss={close}
visible={visible}
style={{ maxHeight: 0.6 * Dimensions.get('window').height }}
- >
- Alert
-
-
-
- Material is the metaphor
- {'\n'}
- {'\n'}A material metaphor is the unifying theory of a rationalized
- space and a system of motion. The material is grounded in tactile
- reality, inspired by the study of paper and ink, yet technologically
- advanced and open to imagination and magic.
- {'\n'}
- {'\n'}
- Surfaces and edges of the material provide visual cues that are
- grounded in reality. The use of familiar tactile attributes helps
- users quickly understand affordances. Yet the flexibility of the
- material creates new affordances that supersede those in the
- physical world, without breaking the rules of physics.
- {'\n'}
- {'\n'}
- The fundamentals of light, surface, and movement are key to
- conveying how objects move, interact, and exist in space and in
- relation to each other. Realistic lighting shows seams, divides
- space, and indicates moving parts.
- {'\n'}
- {'\n'}A material metaphor is the unifying theory of a rationalized
- space and a system of motion. The material is grounded in tactile
- reality, inspired by the study of paper and ink, yet technologically
- advanced and open to imagination and magic.
- {'\n'}
- {'\n'}
- Surfaces and edges of the material provide visual cues that are
- grounded in reality. The use of familiar tactile attributes helps
- users quickly understand affordances. Yet the flexibility of the
- material creates new affordances that supersede those in the
- physical world, without breaking the rules of physics.
- {'\n'}
- {'\n'}
- The fundamentals of light, surface, and movement are key to
- conveying how objects move, interact, and exist in space and in
- relation to each other. Realistic lighting shows seams, divides
- space, and indicates moving parts.
-
-
-
-
- Ok
-
-
+ title="Alert"
+ scrollable
+ scrollAreaProps={{ style: styles.scrollArea }}
+ scrollViewProps={{ contentContainerStyle: styles.scrollViewContent }}
+ content={
+ 'Material is the metaphor\n\nA material metaphor is the unifying theory of a rationalized space and a system of motion. The material is grounded in tactile reality, inspired by the study of paper and ink, yet technologically advanced and open to imagination and magic.\n\nSurfaces and edges of the material provide visual cues that are grounded in reality. The use of familiar tactile attributes helps users quickly understand affordances. Yet the flexibility of the material creates new affordances that supersede those in the physical world, without breaking the rules of physics.\n\nThe fundamentals of light, surface, and movement are key to conveying how objects move, interact, and exist in space and in relation to each other. Realistic lighting shows seams, divides space, and indicates moving parts.\n\nA material metaphor is the unifying theory of a rationalized space and a system of motion. The material is grounded in tactile reality, inspired by the study of paper and ink, yet technologically advanced and open to imagination and magic.\n\nSurfaces and edges of the material provide visual cues that are grounded in reality. The use of familiar tactile attributes helps users quickly understand affordances. Yet the flexibility of the material creates new affordances that supersede those in the physical world, without breaking the rules of physics.\n\nThe fundamentals of light, surface, and movement are key to conveying how objects move, interact, and exist in space and in relation to each other. Realistic lighting shows seams, divides space, and indicates moving parts.'
+ }
+ actions={[
+
+ Ok
+ ,
+ ]}
+ />
);
const styles = StyleSheet.create({
- smallPadding: {
+ scrollArea: {
paddingHorizontal: 0,
},
- biggerPadding: {
+ scrollViewContent: {
paddingHorizontal: 24,
},
});
diff --git a/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx b/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx
index 966422369e..eac4636b5f 100644
--- a/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx
+++ b/example/src/Examples/Dialogs/DialogWithRadioBtns.tsx
@@ -1,16 +1,16 @@
import * as React from 'react';
-import { ScrollView, View, StyleSheet } from 'react-native';
+import { View, StyleSheet } from 'react-native';
import {
- Button,
Portal,
Dialog,
RadioButton,
+ Text,
TouchableRipple,
+ useTheme,
+ Button,
} from 'react-native-paper';
-import { TextComponent } from './DialogTextComponent';
-
type Props = {
visible: boolean;
close: () => void;
@@ -20,74 +20,94 @@ type CheckedState = 'normal' | 'first' | 'second' | 'third' | 'fourth';
const DialogWithRadioBtns = ({ visible, close }: Props) => {
const [checked, setChecked] = React.useState('normal');
+ const theme = useTheme();
+ const optionTextColor = { color: theme.colors.onSurfaceVariant };
return (
-
- Choose an option
-
-
-
- setChecked('normal')}>
-
-
-
-
-
- Option 1
-
+
+ setChecked('normal')}>
+
+
+
-
- setChecked('second')}>
-
-
-
-
-
- Option 2
-
+
+ Option 1
+
+
+
+ setChecked('second')}>
+
+
+
-
- setChecked('third')}>
-
-
-
-
-
- Option 3
-
+
+ Option 2
+
+
+
+ setChecked('third')}>
+
+
+
-
- setChecked('fourth')}>
-
-
-
-
-
- Option 4
-
+
+ Option 3
+
+
+
+ setChecked('fourth')}>
+
+
+
-
-
-
-
-
- Cancel
- Ok
-
-
+
+ Option 4
+
+
+
+
+ }
+ actions={[
+
+ Cancel
+ ,
+
+ Ok
+ ,
+ ]}
+ />
);
};
diff --git a/example/src/Examples/Dialogs/UndismissableDialog.tsx b/example/src/Examples/Dialogs/UndismissableDialog.tsx
index 208c809967..1dad790030 100644
--- a/example/src/Examples/Dialogs/UndismissableDialog.tsx
+++ b/example/src/Examples/Dialogs/UndismissableDialog.tsx
@@ -1,6 +1,4 @@
-import { Button, Portal, Dialog, Palette } from 'react-native-paper';
-
-import { TextComponent } from './DialogTextComponent';
+import { Button, Dialog, Palette, Portal } from 'react-native-paper';
const UndismissableDialog = ({
visible,
@@ -10,18 +8,26 @@ const UndismissableDialog = ({
close: () => void;
}) => (
-
- Alert
-
- This is an undismissable dialog!!
-
-
-
+
Disagree
-
- Agree
-
-
+ ,
+
+ Agree
+ ,
+ ]}
+ />
);
diff --git a/src/components/Dialog/Dialog.tsx b/src/components/Dialog/Dialog.tsx
index a7b082fe89..358d766e08 100644
--- a/src/components/Dialog/Dialog.tsx
+++ b/src/components/Dialog/Dialog.tsx
@@ -1,18 +1,21 @@
import * as React from 'react';
-import { Animated, Platform, StyleSheet } from 'react-native';
-import type { StyleProp, ViewStyle } from 'react-native';
+import { Animated, Platform, ScrollView, StyleSheet } from 'react-native';
+import type { ScrollViewProps, StyleProp, ViewStyle } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import DialogActions from './DialogActions';
import DialogContent from './DialogContent';
+import type { Props as DialogContentProps } from './DialogContent';
import DialogIcon from './DialogIcon';
import DialogScrollArea from './DialogScrollArea';
+import type { Props as DialogScrollAreaProps } from './DialogScrollArea';
import DialogTitle from './DialogTitle';
import { useInternalTheme } from '../../core/theming';
import type { ThemeProp } from '../../types';
+import type { IconSource } from '../Icon';
import Modal from '../Modal';
-import type { DialogChildProps } from './utils';
+import Text from '../Typography/Text';
export type Props = {
/**
@@ -32,9 +35,44 @@ export type Props = {
*/
visible: boolean;
/**
- * Content of the `Dialog`.
+ * Icon to display above the dialog title.
*/
- children: React.ReactNode;
+ icon?: IconSource;
+ /**
+ * Title of the dialog.
+ */
+ title?: React.ReactNode;
+ /**
+ * Content of the dialog. Non-empty strings are rendered as Material 3
+ * supporting text.
+ */
+ content?: React.ReactNode;
+ /**
+ * Action buttons displayed at the bottom of the dialog.
+ * Keep their order stable between renders.
+ */
+ actions?: React.ReactNode[];
+ /**
+ * Whether to render the content in a `ScrollView` within the dialog scroll
+ * area.
+ */
+ scrollable?: boolean;
+ /**
+ * Props passed to `Dialog.Content` when `scrollable` is not enabled.
+ */
+ contentProps?: Omit;
+ /**
+ * Props passed to `Dialog.ScrollArea` when `scrollable` is enabled.
+ */
+ scrollAreaProps?: Omit;
+ /**
+ * Props passed to the `ScrollView` when `scrollable` is enabled.
+ */
+ scrollViewProps?: Omit;
+ /**
+ * Accessibility label for the dialog. This is read by the screen reader when the user opens a dialog.
+ */
+ 'aria-label'?: string;
style?: Animated.WithAnimatedValue>;
/**
* @optional
@@ -46,8 +84,6 @@ export type Props = {
testID?: string;
};
-const DIALOG_ELEVATION: number = 24;
-
/**
* Dialogs inform users about a specific task and may contain critical information, require decisions, or involve multiple tasks.
* To render the `Dialog` above other components, you'll need to wrap it with the [`Portal`](../Portal) component.
@@ -56,7 +92,7 @@ const DIALOG_ELEVATION: number = 24;
* ```js
* import * as React from 'react';
* import { View } from 'react-native';
- * import { Button, Dialog, Portal, PaperProvider, Text } from 'react-native-paper';
+ * import { Button, Dialog, Portal, PaperProvider } from 'react-native-paper';
*
* const MyComponent = () => {
* const [visible, setVisible] = React.useState(false);
@@ -70,15 +106,13 @@ const DIALOG_ELEVATION: number = 24;
*
* Show Dialog
*
- *
- * Alert
- *
- * This is simple dialog
- *
- *
- * Done
- *
- *
+ *
*
*
*
@@ -89,7 +123,6 @@ const DIALOG_ELEVATION: number = 24;
* ```
*/
const Dialog = ({
- children,
dismissable = true,
dismissableBackButton = dismissable,
onDismiss,
@@ -97,6 +130,15 @@ const Dialog = ({
style,
theme: themeOverrides,
testID,
+ actions,
+ content,
+ icon,
+ scrollable,
+ contentProps,
+ scrollAreaProps,
+ scrollViewProps,
+ title,
+ 'aria-label': ariaLabel,
}: Props) => {
const { right, left } = useSafeAreaInsets();
const theme = useInternalTheme(themeOverrides);
@@ -104,6 +146,18 @@ const Dialog = ({
const backgroundColor = theme.colors.surfaceContainerHigh;
+ const contentNode =
+ typeof content === 'string' ? (
+
+ {content}
+
+ ) : (
+ content
+ );
+
return (
- {React.Children.toArray(children)
- .filter((child) => child != null && typeof child !== 'boolean')
- .map((child, i) => {
- if (i === 0 && React.isValidElement(child)) {
- return React.cloneElement(child, {
- style: [{ marginTop: 24 }, child.props.style],
- });
- }
+ {icon ? : null}
+
+ {title ? (
+
+ {title}
+
+ ) : null}
+
+ {scrollable ? (
+
+ {contentNode}
+
+ ) : (
+
+ {contentNode}
+
+ )}
- return child;
- })}
+ {actions?.length ? {actions} : null}
);
};
@@ -158,8 +231,15 @@ const styles = StyleSheet.create({
* dialog (44 pixel from the top and bottom) it won't be dismissed.
*/
marginVertical: Platform.OS === 'android' ? 44 : 0,
- elevation: DIALOG_ELEVATION,
justifyContent: 'flex-start',
+ minWidth: 280,
+ maxWidth: 560,
+ },
+ titleWithIcon: {
+ textAlign: 'center',
+ },
+ firstChild: {
+ marginTop: 24,
},
});
diff --git a/src/components/Dialog/DialogActions.tsx b/src/components/Dialog/DialogActions.tsx
index 7e3799451e..2aff5e8748 100644
--- a/src/components/Dialog/DialogActions.tsx
+++ b/src/components/Dialog/DialogActions.tsx
@@ -2,7 +2,6 @@ import * as React from 'react';
import { StyleSheet, View } from 'react-native';
import type { StyleProp, ViewProps, ViewStyle } from 'react-native';
-import type { DialogActionChildProps } from './utils';
import { useInternalTheme } from '../../core/theming';
import type { ThemeProp } from '../../types';
@@ -33,12 +32,18 @@ export type Props = ViewProps & {
*
* return (
*
- *
- *
- * console.log('Cancel')}>Cancel
- * console.log('Ok')}>Ok
- *
- *
+ *
+ * Disagree
+ * ,
+ *
+ * Agree
+ * ,
+ * ]}
+ * />
*
* );
* };
@@ -46,26 +51,26 @@ export type Props = ViewProps & {
* export default MyComponent;
* ```
*/
-const DialogActions = (props: Props) => {
- useInternalTheme(props.theme);
- const actionsLength = React.Children.toArray(props.children).length;
+const DialogActions = ({ children, style, theme, ...rest }: Props) => {
+ useInternalTheme(theme);
+
+ const actions = React.Children.toArray(children).filter((child) =>
+ React.isValidElement<{ style?: StyleProp }>(child)
+ );
return (
-
- {React.Children.map(props.children, (child, i) =>
- React.isValidElement(child)
- ? React.cloneElement(child, {
- compact: true,
- uppercase: false,
- style: [
- {
- marginRight: i + 1 === actionsLength ? 0 : 8,
- },
- child.props.style,
- ],
- })
- : child
- )}
+
+ {actions.map((child, index) => (
+
+ {child}
+
+ ))}
);
};
@@ -81,6 +86,12 @@ const styles = StyleSheet.create({
paddingBottom: 24,
paddingHorizontal: 24,
},
+ item: {
+ marginRight: 8,
+ },
+ itemLast: {
+ marginRight: 0,
+ },
});
export default DialogActions;
diff --git a/src/components/Dialog/DialogContent.tsx b/src/components/Dialog/DialogContent.tsx
index a084188b32..374a790185 100644
--- a/src/components/Dialog/DialogContent.tsx
+++ b/src/components/Dialog/DialogContent.tsx
@@ -25,11 +25,7 @@ export type Props = ViewProps & {
*
* return (
*
- *
- *
- * This is simple dialog
- *
- *
+ *
*
* );
* };
diff --git a/src/components/Dialog/DialogIcon.tsx b/src/components/Dialog/DialogIcon.tsx
index 3ced9e12b0..bee3712290 100644
--- a/src/components/Dialog/DialogIcon.tsx
+++ b/src/components/Dialog/DialogIcon.tsx
@@ -32,7 +32,6 @@ export type Props = {
* ## Usage
* ```js
* import * as React from 'react';
- * import { StyleSheet } from 'react-native';
* import { Dialog, Portal, Text } from 'react-native-paper';
*
* const MyComponent = () => {
@@ -42,23 +41,11 @@ export type Props = {
*
* return (
*
- *
- *
- * This is a title
- *
- * This is simple dialog
- *
- *
+ *
*
* );
* };
*
- * const styles = StyleSheet.create({
- * title: {
- * textAlign: 'center',
- * },
- * })
- *
* export default MyComponent;
* ```
*/
@@ -71,7 +58,7 @@ const DialogIcon = ({
const theme = useInternalTheme(themeOverrides);
const { colors } = theme;
- //@ts-ignore
+ // @ts-ignore
const iconColor = color || colors.secondary;
return (
diff --git a/src/components/Dialog/DialogScrollArea.tsx b/src/components/Dialog/DialogScrollArea.tsx
index a46824be45..340aca4a75 100644
--- a/src/components/Dialog/DialogScrollArea.tsx
+++ b/src/components/Dialog/DialogScrollArea.tsx
@@ -34,13 +34,7 @@ export type Props = ViewProps & {
*
* return (
*
- *
- *
- *
- * This is a scrollable area
- *
- *
- *
+ *
*
* );
* };
@@ -52,7 +46,7 @@ const DialogScrollArea = (props: Props) => {
const theme = useInternalTheme(props.theme);
const { colors } = theme;
const borderStyles = {
- borderColor: colors.surfaceVariant,
+ borderColor: colors.outlineVariant,
borderTopWidth: 1,
borderBottomWidth: 1,
};
diff --git a/src/components/Dialog/DialogTitle.tsx b/src/components/Dialog/DialogTitle.tsx
index ae553daee2..e76f1e8209 100644
--- a/src/components/Dialog/DialogTitle.tsx
+++ b/src/components/Dialog/DialogTitle.tsx
@@ -33,12 +33,7 @@ export type Props = React.ComponentPropsWithRef & {
*
* return (
*
- *
- * This is a title
- *
- * This is simple dialog
- *
- *
+ *
*
* );
* };
diff --git a/src/components/Dialog/utils.ts b/src/components/Dialog/utils.ts
deleted file mode 100644
index 64ccec77cc..0000000000
--- a/src/components/Dialog/utils.ts
+++ /dev/null
@@ -1,10 +0,0 @@
-import type { StyleProp, ViewStyle } from 'react-native';
-
-export type DialogChildProps = {
- style?: StyleProp;
-};
-
-export type DialogActionChildProps = DialogChildProps & {
- compact?: boolean;
- uppercase?: boolean;
-};
diff --git a/src/components/Modal.tsx b/src/components/Modal.tsx
index 3c66c885b3..18803b56dc 100644
--- a/src/components/Modal.tsx
+++ b/src/components/Modal.tsx
@@ -32,6 +32,10 @@ export type Props = {
* Accessibility label for the overlay. This is read by the screen reader when the user taps outside the modal.
*/
overlayAccessibilityLabel?: string;
+ /**
+ * Accessibility label for the dialog. This is read by the screen reader when the user opens a dialog.
+ */
+ 'aria-label'?: string;
/**
* Determines Whether the modal is visible.
*/
@@ -101,6 +105,7 @@ function Modal({
dismissableBackButton = dismissable,
visible = false,
overlayAccessibilityLabel = 'Close modal',
+ 'aria-label': ariaLabel,
onDismiss = () => {},
children,
contentContainerStyle,
@@ -220,6 +225,7 @@ function Modal({
theme={theme}
style={[{ opacity }, styles.content, contentContainerStyle]}
container
+ aria-label={ariaLabel}
>
{children}
diff --git a/src/components/__tests__/Dialog.test.tsx b/src/components/__tests__/Dialog.test.tsx
index 32477e5fe1..6c8bd4e5b9 100644
--- a/src/components/__tests__/Dialog.test.tsx
+++ b/src/components/__tests__/Dialog.test.tsx
@@ -21,11 +21,9 @@ interface BackHandlerStatic extends RNBackHandlerStatic {
const BackHandler = RNBackHandler as BackHandlerStatic;
describe('Dialog', () => {
- it('should render passed children', async () => {
+ it('should render passed content', async () => {
await render(
-
- This is simple dialog
-
+
);
expect(screen.getByTestId('dialog')).toHaveTextContent(
@@ -36,9 +34,13 @@ describe('Dialog', () => {
it('should call onDismiss when dismissable', async () => {
const onDismiss = jest.fn();
await render(
-
- This is simple dialog
-
+
);
await userEvent.press(screen.getByTestId('dialog-backdrop'));
@@ -52,9 +54,13 @@ describe('Dialog', () => {
it('should not call onDismiss when dismissable is false', async () => {
const onDismiss = jest.fn();
await render(
-
- This is simple dialog
-
+
);
await userEvent.press(screen.getByTestId('dialog-backdrop'));
@@ -75,9 +81,8 @@ describe('Dialog', () => {
dismissable={false}
dismissableBackButton
testID="dialog"
- >
- This is simple dialog
-
+ content="This is simple dialog"
+ />
);
await userEvent.press(screen.getByTestId('dialog-backdrop'));
@@ -96,26 +101,109 @@ describe('Dialog', () => {
it('should apply top margin to the first child if the dialog is V3', async () => {
await render(
-
-
- Test Dialog Content
-
-
+ This is simple dialog}
+ content="This is simple dialog"
+ />
);
- expect(screen.getByTestId('dialog-content')).toHaveStyle({
+ const element = screen.getByTestId('dialog-title').parent;
+
+ expect(element).toHaveStyle({
marginTop: 24,
});
});
+
+ it('should render content in a scroll area', async () => {
+ await render(
+
+ );
+
+ expect(screen.getByTestId('dialog-scroll-area')).toBeOnTheScreen();
+ expect(screen.getByTestId('dialog-scroll-view')).toBeOnTheScreen();
+ expect(screen.getByText('Scrollable content')).toBeOnTheScreen();
+ });
+
+ it('should render passed action', async () => {
+ await render(
+ jest.fn()} testID="cancel-btn">
+ Cancel
+ ,
+ ]}
+ />
+ );
+
+ expect(screen.getByTestId('cancel-btn')).toBeOnTheScreen();
+ });
+
+ it('should render passed content if no title or accessibilityLabel were passed', async () => {
+ await render(
+
+ );
+
+ expect(screen.getByTestId('dialog-surface')).toHaveAccessibleName(
+ 'This is simple dialog'
+ );
+ });
+
+ it('should render passed title as a default accessibility label', async () => {
+ await render(
+
+ );
+
+ expect(screen.getByTestId('dialog-surface')).toHaveAccessibleName(
+ 'dialog-title'
+ );
+ });
+
+ it('should render passed accessibility label', async () => {
+ await render(
+
+ );
+
+ expect(screen.getByTestId('dialog-surface')).toHaveAccessibleName(
+ 'dialog-label'
+ );
+ });
});
describe('DialogActions', () => {
- it('should render passed children', async () => {
+ it('should render passed actions', async () => {
await render(
-
- Cancel
- Ok
-
+
+ Cancel
+ ,
+
+ Ok
+ ,
+ ]}
+ />
);
expect(screen.getByTestId('button-cancel')).toBeOnTheScreen();