@fluentui/react-dialog 9.0.0-beta.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (226) hide show
  1. package/CHANGELOG.json +328 -0
  2. package/CHANGELOG.md +152 -0
  3. package/LICENSE +15 -0
  4. package/README.md +5 -0
  5. package/Spec.md +518 -0
  6. package/assets/AlertDialogKeyboardInteraction.png +0 -0
  7. package/assets/AlertDialogMouseInteraction.png +0 -0
  8. package/assets/ModalDialogKeyboardInteraction.png +0 -0
  9. package/assets/ModalDialogMouseInteraction.png +0 -0
  10. package/assets/NonModalDialogKeyboardInteraction.png +0 -0
  11. package/assets/NonModalDialogMouseInteraction.png +0 -0
  12. package/dist/index.d.ts +406 -0
  13. package/dist/tsdoc-metadata.json +11 -0
  14. package/lib/Dialog.js +2 -0
  15. package/lib/Dialog.js.map +1 -0
  16. package/lib/DialogActions.js +2 -0
  17. package/lib/DialogActions.js.map +1 -0
  18. package/lib/DialogBody.js +2 -0
  19. package/lib/DialogBody.js.map +1 -0
  20. package/lib/DialogSurface.js +2 -0
  21. package/lib/DialogSurface.js.map +1 -0
  22. package/lib/DialogTitle.js +2 -0
  23. package/lib/DialogTitle.js.map +1 -0
  24. package/lib/DialogTrigger.js +2 -0
  25. package/lib/DialogTrigger.js.map +1 -0
  26. package/lib/components/Dialog/Dialog.js +21 -0
  27. package/lib/components/Dialog/Dialog.js.map +1 -0
  28. package/lib/components/Dialog/Dialog.types.js +2 -0
  29. package/lib/components/Dialog/Dialog.types.js.map +1 -0
  30. package/lib/components/Dialog/index.js +6 -0
  31. package/lib/components/Dialog/index.js.map +1 -0
  32. package/lib/components/Dialog/renderDialog.js +26 -0
  33. package/lib/components/Dialog/renderDialog.js.map +1 -0
  34. package/lib/components/Dialog/useDialog.js +197 -0
  35. package/lib/components/Dialog/useDialog.js.map +1 -0
  36. package/lib/components/Dialog/useDialogContextValues.js +31 -0
  37. package/lib/components/Dialog/useDialogContextValues.js.map +1 -0
  38. package/lib/components/Dialog/useDialogStyles.js +41 -0
  39. package/lib/components/Dialog/useDialogStyles.js.map +1 -0
  40. package/lib/components/DialogActions/DialogActions.js +16 -0
  41. package/lib/components/DialogActions/DialogActions.js.map +1 -0
  42. package/lib/components/DialogActions/DialogActions.types.js +2 -0
  43. package/lib/components/DialogActions/DialogActions.types.js.map +1 -0
  44. package/lib/components/DialogActions/index.js +6 -0
  45. package/lib/components/DialogActions/index.js.map +1 -0
  46. package/lib/components/DialogActions/renderDialogActions.js +16 -0
  47. package/lib/components/DialogActions/renderDialogActions.js.map +1 -0
  48. package/lib/components/DialogActions/useDialogActions.js +27 -0
  49. package/lib/components/DialogActions/useDialogActions.js.map +1 -0
  50. package/lib/components/DialogActions/useDialogActionsStyles.js +51 -0
  51. package/lib/components/DialogActions/useDialogActionsStyles.js.map +1 -0
  52. package/lib/components/DialogBody/DialogBody.js +16 -0
  53. package/lib/components/DialogBody/DialogBody.js.map +1 -0
  54. package/lib/components/DialogBody/DialogBody.types.js +2 -0
  55. package/lib/components/DialogBody/DialogBody.types.js.map +1 -0
  56. package/lib/components/DialogBody/index.js +6 -0
  57. package/lib/components/DialogBody/index.js.map +1 -0
  58. package/lib/components/DialogBody/renderDialogBody.js +16 -0
  59. package/lib/components/DialogBody/renderDialogBody.js.map +1 -0
  60. package/lib/components/DialogBody/useDialogBody.js +25 -0
  61. package/lib/components/DialogBody/useDialogBody.js.map +1 -0
  62. package/lib/components/DialogBody/useDialogBodyStyles.js +42 -0
  63. package/lib/components/DialogBody/useDialogBodyStyles.js.map +1 -0
  64. package/lib/components/DialogSurface/DialogSurface.js +18 -0
  65. package/lib/components/DialogSurface/DialogSurface.js.map +1 -0
  66. package/lib/components/DialogSurface/DialogSurface.types.js +2 -0
  67. package/lib/components/DialogSurface/DialogSurface.types.js.map +1 -0
  68. package/lib/components/DialogSurface/index.js +6 -0
  69. package/lib/components/DialogSurface/index.js.map +1 -0
  70. package/lib/components/DialogSurface/renderDialogSurface.js +18 -0
  71. package/lib/components/DialogSurface/renderDialogSurface.js.map +1 -0
  72. package/lib/components/DialogSurface/useDialogSurface.js +59 -0
  73. package/lib/components/DialogSurface/useDialogSurface.js.map +1 -0
  74. package/lib/components/DialogSurface/useDialogSurfaceContextValues.js +7 -0
  75. package/lib/components/DialogSurface/useDialogSurfaceContextValues.js.map +1 -0
  76. package/lib/components/DialogSurface/useDialogSurfaceStyles.js +78 -0
  77. package/lib/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -0
  78. package/lib/components/DialogTitle/DialogTitle.js +17 -0
  79. package/lib/components/DialogTitle/DialogTitle.js.map +1 -0
  80. package/lib/components/DialogTitle/DialogTitle.types.js +2 -0
  81. package/lib/components/DialogTitle/DialogTitle.types.js.map +1 -0
  82. package/lib/components/DialogTitle/index.js +6 -0
  83. package/lib/components/DialogTitle/index.js.map +1 -0
  84. package/lib/components/DialogTitle/renderDialogTitle.js +19 -0
  85. package/lib/components/DialogTitle/renderDialogTitle.js.map +1 -0
  86. package/lib/components/DialogTitle/useDialogTitle.js +42 -0
  87. package/lib/components/DialogTitle/useDialogTitle.js.map +1 -0
  88. package/lib/components/DialogTitle/useDialogTitleStyles.js +109 -0
  89. package/lib/components/DialogTitle/useDialogTitleStyles.js.map +1 -0
  90. package/lib/components/DialogTrigger/DialogTrigger.js +20 -0
  91. package/lib/components/DialogTrigger/DialogTrigger.js.map +1 -0
  92. package/lib/components/DialogTrigger/DialogTrigger.types.js +2 -0
  93. package/lib/components/DialogTrigger/DialogTrigger.types.js.map +1 -0
  94. package/lib/components/DialogTrigger/index.js +5 -0
  95. package/lib/components/DialogTrigger/index.js.map +1 -0
  96. package/lib/components/DialogTrigger/renderDialogTrigger.js +7 -0
  97. package/lib/components/DialogTrigger/renderDialogTrigger.js.map +1 -0
  98. package/lib/components/DialogTrigger/useDialogTrigger.js +65 -0
  99. package/lib/components/DialogTrigger/useDialogTrigger.js.map +1 -0
  100. package/lib/contexts/constants.js +11 -0
  101. package/lib/contexts/constants.js.map +1 -0
  102. package/lib/contexts/dialogContext.js +21 -0
  103. package/lib/contexts/dialogContext.js.map +1 -0
  104. package/lib/contexts/dialogSurfaceContext.js +10 -0
  105. package/lib/contexts/dialogSurfaceContext.js.map +1 -0
  106. package/lib/contexts/index.js +4 -0
  107. package/lib/contexts/index.js.map +1 -0
  108. package/lib/index.js +7 -0
  109. package/lib/index.js.map +1 -0
  110. package/lib/utils/index.js +5 -0
  111. package/lib/utils/index.js.map +1 -0
  112. package/lib/utils/isEscapeKeyDown.js +11 -0
  113. package/lib/utils/isEscapeKeyDown.js.map +1 -0
  114. package/lib/utils/isTargetDisabled.js +14 -0
  115. package/lib/utils/isTargetDisabled.js.map +1 -0
  116. package/lib/utils/localShorthands.js +9 -0
  117. package/lib/utils/localShorthands.js.map +1 -0
  118. package/lib/utils/normalizeDefaultPrevented.js +11 -0
  119. package/lib/utils/normalizeDefaultPrevented.js.map +1 -0
  120. package/lib-commonjs/Dialog.js +10 -0
  121. package/lib-commonjs/Dialog.js.map +1 -0
  122. package/lib-commonjs/DialogActions.js +10 -0
  123. package/lib-commonjs/DialogActions.js.map +1 -0
  124. package/lib-commonjs/DialogBody.js +10 -0
  125. package/lib-commonjs/DialogBody.js.map +1 -0
  126. package/lib-commonjs/DialogSurface.js +10 -0
  127. package/lib-commonjs/DialogSurface.js.map +1 -0
  128. package/lib-commonjs/DialogTitle.js +10 -0
  129. package/lib-commonjs/DialogTitle.js.map +1 -0
  130. package/lib-commonjs/DialogTrigger.js +10 -0
  131. package/lib-commonjs/DialogTrigger.js.map +1 -0
  132. package/lib-commonjs/components/Dialog/Dialog.js +33 -0
  133. package/lib-commonjs/components/Dialog/Dialog.js.map +1 -0
  134. package/lib-commonjs/components/Dialog/Dialog.types.js +6 -0
  135. package/lib-commonjs/components/Dialog/Dialog.types.js.map +1 -0
  136. package/lib-commonjs/components/Dialog/index.js +18 -0
  137. package/lib-commonjs/components/Dialog/index.js.map +1 -0
  138. package/lib-commonjs/components/Dialog/renderDialog.js +39 -0
  139. package/lib-commonjs/components/Dialog/renderDialog.js.map +1 -0
  140. package/lib-commonjs/components/Dialog/useDialog.js +211 -0
  141. package/lib-commonjs/components/Dialog/useDialog.js.map +1 -0
  142. package/lib-commonjs/components/Dialog/useDialogContextValues.js +40 -0
  143. package/lib-commonjs/components/Dialog/useDialogContextValues.js.map +1 -0
  144. package/lib-commonjs/components/Dialog/useDialogStyles.js +53 -0
  145. package/lib-commonjs/components/Dialog/useDialogStyles.js.map +1 -0
  146. package/lib-commonjs/components/DialogActions/DialogActions.js +27 -0
  147. package/lib-commonjs/components/DialogActions/DialogActions.js.map +1 -0
  148. package/lib-commonjs/components/DialogActions/DialogActions.types.js +6 -0
  149. package/lib-commonjs/components/DialogActions/DialogActions.types.js.map +1 -0
  150. package/lib-commonjs/components/DialogActions/index.js +18 -0
  151. package/lib-commonjs/components/DialogActions/index.js.map +1 -0
  152. package/lib-commonjs/components/DialogActions/renderDialogActions.js +27 -0
  153. package/lib-commonjs/components/DialogActions/renderDialogActions.js.map +1 -0
  154. package/lib-commonjs/components/DialogActions/useDialogActions.js +37 -0
  155. package/lib-commonjs/components/DialogActions/useDialogActions.js.map +1 -0
  156. package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js +63 -0
  157. package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js.map +1 -0
  158. package/lib-commonjs/components/DialogBody/DialogBody.js +27 -0
  159. package/lib-commonjs/components/DialogBody/DialogBody.js.map +1 -0
  160. package/lib-commonjs/components/DialogBody/DialogBody.types.js +6 -0
  161. package/lib-commonjs/components/DialogBody/DialogBody.types.js.map +1 -0
  162. package/lib-commonjs/components/DialogBody/index.js +18 -0
  163. package/lib-commonjs/components/DialogBody/index.js.map +1 -0
  164. package/lib-commonjs/components/DialogBody/renderDialogBody.js +27 -0
  165. package/lib-commonjs/components/DialogBody/renderDialogBody.js.map +1 -0
  166. package/lib-commonjs/components/DialogBody/useDialogBody.js +36 -0
  167. package/lib-commonjs/components/DialogBody/useDialogBody.js.map +1 -0
  168. package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js +55 -0
  169. package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js.map +1 -0
  170. package/lib-commonjs/components/DialogSurface/DialogSurface.js +30 -0
  171. package/lib-commonjs/components/DialogSurface/DialogSurface.js.map +1 -0
  172. package/lib-commonjs/components/DialogSurface/DialogSurface.types.js +6 -0
  173. package/lib-commonjs/components/DialogSurface/DialogSurface.types.js.map +1 -0
  174. package/lib-commonjs/components/DialogSurface/index.js +18 -0
  175. package/lib-commonjs/components/DialogSurface/index.js.map +1 -0
  176. package/lib-commonjs/components/DialogSurface/renderDialogSurface.js +30 -0
  177. package/lib-commonjs/components/DialogSurface/renderDialogSurface.js.map +1 -0
  178. package/lib-commonjs/components/DialogSurface/useDialogSurface.js +72 -0
  179. package/lib-commonjs/components/DialogSurface/useDialogSurface.js.map +1 -0
  180. package/lib-commonjs/components/DialogSurface/useDialogSurfaceContextValues.js +16 -0
  181. package/lib-commonjs/components/DialogSurface/useDialogSurfaceContextValues.js.map +1 -0
  182. package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js +90 -0
  183. package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -0
  184. package/lib-commonjs/components/DialogTitle/DialogTitle.js +28 -0
  185. package/lib-commonjs/components/DialogTitle/DialogTitle.js.map +1 -0
  186. package/lib-commonjs/components/DialogTitle/DialogTitle.types.js +6 -0
  187. package/lib-commonjs/components/DialogTitle/DialogTitle.types.js.map +1 -0
  188. package/lib-commonjs/components/DialogTitle/index.js +18 -0
  189. package/lib-commonjs/components/DialogTitle/index.js.map +1 -0
  190. package/lib-commonjs/components/DialogTitle/renderDialogTitle.js +31 -0
  191. package/lib-commonjs/components/DialogTitle/renderDialogTitle.js.map +1 -0
  192. package/lib-commonjs/components/DialogTitle/useDialogTitle.js +56 -0
  193. package/lib-commonjs/components/DialogTitle/useDialogTitle.js.map +1 -0
  194. package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js +123 -0
  195. package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js.map +1 -0
  196. package/lib-commonjs/components/DialogTrigger/DialogTrigger.js +31 -0
  197. package/lib-commonjs/components/DialogTrigger/DialogTrigger.js.map +1 -0
  198. package/lib-commonjs/components/DialogTrigger/DialogTrigger.types.js +6 -0
  199. package/lib-commonjs/components/DialogTrigger/DialogTrigger.types.js.map +1 -0
  200. package/lib-commonjs/components/DialogTrigger/index.js +16 -0
  201. package/lib-commonjs/components/DialogTrigger/index.js.map +1 -0
  202. package/lib-commonjs/components/DialogTrigger/renderDialogTrigger.js +16 -0
  203. package/lib-commonjs/components/DialogTrigger/renderDialogTrigger.js.map +1 -0
  204. package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js +80 -0
  205. package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js.map +1 -0
  206. package/lib-commonjs/contexts/constants.js +17 -0
  207. package/lib-commonjs/contexts/constants.js.map +1 -0
  208. package/lib-commonjs/contexts/dialogContext.js +32 -0
  209. package/lib-commonjs/contexts/dialogContext.js.map +1 -0
  210. package/lib-commonjs/contexts/dialogSurfaceContext.js +21 -0
  211. package/lib-commonjs/contexts/dialogSurfaceContext.js.map +1 -0
  212. package/lib-commonjs/contexts/index.js +14 -0
  213. package/lib-commonjs/contexts/index.js.map +1 -0
  214. package/lib-commonjs/index.js +193 -0
  215. package/lib-commonjs/index.js.map +1 -0
  216. package/lib-commonjs/utils/index.js +16 -0
  217. package/lib-commonjs/utils/index.js.map +1 -0
  218. package/lib-commonjs/utils/isEscapeKeyDown.js +22 -0
  219. package/lib-commonjs/utils/isEscapeKeyDown.js.map +1 -0
  220. package/lib-commonjs/utils/isTargetDisabled.js +23 -0
  221. package/lib-commonjs/utils/isTargetDisabled.js.map +1 -0
  222. package/lib-commonjs/utils/localShorthands.js +18 -0
  223. package/lib-commonjs/utils/localShorthands.js.map +1 -0
  224. package/lib-commonjs/utils/normalizeDefaultPrevented.js +20 -0
  225. package/lib-commonjs/utils/normalizeDefaultPrevented.js.map +1 -0
  226. package/package.json +69 -0
package/Spec.md ADDED
@@ -0,0 +1,518 @@
1
+ # Dialog
2
+
3
+ ## Background
4
+
5
+ This spec defines the default function of a `Dialog` a window overlaid on either the primary window or another dialog window. Windows under a modal dialog are inert. That is, users cannot interact with content outside an active dialog window. Inert content outside an active dialog is typically visually obscured or dimmed so it is difficult to discern, and in some implementations, attempts to interact with the inert content cause the dialog to close.
6
+
7
+ The interactions that result in the opening/closing of the `Dialog` component should be configurable.
8
+
9
+ ## Prior Art
10
+
11
+ - All mentions of v7 or v8 refer to Fabric - `@fluentui/react` ([docsite](https://developer.microsoft.com/en-us/fluentui#/))
12
+ - All mentions of v0 refer to Northstar - `@fluentui/react-northstar` ([docsite](https://fluentsite.z22.web.core.windows.net/))
13
+
14
+ - [Github epic](https://github.com/microsoft/fluentui/issues/20953)
15
+ - [Open UI Research](https://open-ui.org/components/dialog.research)
16
+ - Dialogs in 3rd party UI systems:
17
+ - [Carbon](https://react.carbondesignsystem.com/?path=/docs/components-modal--default)
18
+ - [Chakra UI](https://chakra-ui.com/docs/overlay/modal)
19
+ - [FAST](https://explore.fast.design/components/fast-dialog)
20
+ - [Material UI](https://mui.com/components/dialogs/)
21
+ - [Radix](https://www.radix-ui.com/docs/primitives/components/dialog)
22
+ - [Reach UI](https://reach.tech/dialog/)
23
+ - [Reakit](https://reakit.io/docs/dialog/)
24
+ - [Ariakit](https://github.com/reakit/reakit/tree/v2)
25
+ - [Spectrum](https://react-spectrum.adobe.com/react-spectrum/Dialog.html)
26
+
27
+ ### Comparison between v0 and v8
28
+
29
+ Note that the below code samples are not meant to be complete, but to highlight differences between the two libraries. Please refer to official docsites for actual API references.
30
+
31
+ #### v8
32
+
33
+ In v8 there are Dialog and Modal components which are relevant to the Dialog component for v9. The Dialog component was intended to be used primarily for confirming actions, whereas Modal component was intended to be used for lengthy content that may contain forms and other controls. This spec will only cover the comparison to the Dialog component.
34
+
35
+ The visibility of the dialog is controlled through the `hidden` prop whose its value should be a react state boolean provided from the consumer.
36
+
37
+ [Documentation for v8 Dialog](https://developer.microsoft.com/en-us/fluentui#/controls/web/dialog)
38
+
39
+ Sample code:
40
+
41
+ ```jsx
42
+ <DefaultButton secondaryText="Opens the Sample Dialog" onClick={toggleHideDialog} text="Open Dialog" />
43
+
44
+ <Dialog
45
+ hidden={hideDialog}
46
+ onDismiss={toggleHideDialog}
47
+ dialogContentProps={dialogContentProps}
48
+ modalProps={modalProps}
49
+ >
50
+ <DialogFooter>
51
+ <PrimaryButton onClick={toggleHideDialog} text="Send" />
52
+ <DefaultButton onClick={toggleHideDialog} text="Don't send" />
53
+ </DialogFooter>
54
+ </Dialog>
55
+
56
+ ```
57
+
58
+ #### v0
59
+
60
+ In v0, the Dialog component expects all the content through props, including the content, actions etc. The dialog component uses the `trigger` prop that expects a React component to control its visibility. The element passed to this prop will be rendered in-place where the dialog is defined.
61
+
62
+ [Documentation for v0 Dialog](https://fluentsite.z22.web.core.windows.net/components/dialog/definition)
63
+
64
+ ```jsx
65
+ <Dialog
66
+ cancelButton="Connect protocol"
67
+ confirmButton="Transmit capacitor"
68
+ content="Connect driver"
69
+ header="Transmit capacitor"
70
+ headerAction="Generate protocol"
71
+ trigger={<Button content="A trigger" />}
72
+ />
73
+ ```
74
+
75
+ ## API
76
+
77
+ The `Dialog` should implement a `children` based API as is one of the standards across all the surveyed alternatives as a part of Open UI research in [Prior Art](#prior-art). The component will leverage the use of `context` in the interaction and data flows of child compound components.
78
+
79
+ Sample usages will be give in the following section of this document [Sample code](#sample-code)
80
+
81
+ ### Dialog
82
+
83
+ The root level component serves as an interface for interaction with all possible behaviors exposed. It provides context down the hierarchy to `children` compound components to allow functionality. This component expects to receive as children either a `DialogSurface` or a `DialogTrigger` and a `DialogSurface` (or some component that will eventually render one of those compound components) in this specific order
84
+
85
+ ```tsx
86
+ type DialogSlots = {
87
+ /**
88
+ * Dimmed background of dialog.
89
+ * The default overlay is rendered as a `<div>` with styling.
90
+ * This slot expects a `<div>` element which will replace the default overlay.
91
+ * The overlay should have `aria-hidden="true"`.
92
+ */
93
+ overlay?: Slot<'div'>;
94
+ /**
95
+ * The root element of the Dialog right after Portal.
96
+ */
97
+ root: Slot<'div'>;
98
+ };
99
+
100
+ type DialogProps = ComponentProps<DialogSlots> & {
101
+ /**
102
+ * Dialog variations.
103
+ *
104
+ * `modal`: When this type of dialog is open, the rest of the page is dimmed out and cannot be interacted with. The tab sequence is kept within the dialog and moving the focus outside the dialog will imply closing it. This is the default type of the component.
105
+ *
106
+ * `non-modal`: When a non-modal dialog is open, the rest of the page is not dimmed out and users can interact with the rest of the page. This also implies that the tab focus can move outside the dialog when it reaches the last focusable element.
107
+ *
108
+ * `alert`: is a special type of modal dialogs that interrupts the user's workflow to communicate an important message or ask for a decision. Unlike a typical modal dialog, the user must take an action through the options given to dismiss the dialog, and it cannot be dismissed through the dimmed background or escape key.
109
+ *
110
+ * @default 'modal'
111
+ */
112
+ modalType?: 'modal' | 'non-modal' | 'alert';
113
+ /**
114
+ * Controls the open state of the dialog
115
+ * @default undefined
116
+ */
117
+ open?: boolean;
118
+ /**
119
+ * Default value for the uncontrolled open state of the dialog.
120
+ * @default false
121
+ */
122
+ defaultOpen?: boolean;
123
+ /**
124
+ * Callback fired when the component changes value from open state.
125
+ * @default undefined
126
+ */
127
+ onOpenChange?(event: MouseEvent | KeyboardEvent, data: DialogOpenChangeData): void;
128
+ };
129
+
130
+ type DialogOpenChangeData = {
131
+ /**
132
+ * The event source of the callback invocation
133
+ */
134
+ type: 'escapeKeyDown' | 'overlayClick' | 'triggerClick';
135
+ /**
136
+ * The next value for the internal state of the dialog
137
+ */
138
+ open: boolean;
139
+ };
140
+ ```
141
+
142
+ ### DialogTrigger
143
+
144
+ A non-visual component that wraps its child and configures them to be the trigger that will open or close a `Dialog`. This component should only accept one child.
145
+
146
+ In case the trigger is used outside `Dialog` component it'll still provide basic [ARIA related attributes](#aria-roles-and-states) to it's wrapped child, but it won't be able to alter the dialog `open` state anymore, in that case the user must provide a [`controlled state`](#controlled-dialog)
147
+
148
+ ```typescript
149
+ export type DialogTriggerProps = {
150
+ /**
151
+ * Explicitly declare if the trigger is responsible for opening or
152
+ * closing a Dialog visibility state.
153
+ * @default 'open' // if it's outside DialogSurface
154
+ * @default 'close' // if it's inside DialogSurface
155
+ */
156
+ action?: 'open' | 'close';
157
+ /**
158
+ * Explicitly require single child or render function
159
+ * to inject properties
160
+ */
161
+ children: (React.ReactElement & { ref?: React.Ref<unknown> }) | (() => React.ReactElement | null);
162
+ };
163
+ ```
164
+
165
+ ### DialogSurface
166
+
167
+ The `DialogSurface` component represents the visual part of a `Dialog` as a whole, it contains everything that should be visible.
168
+
169
+ ```tsx
170
+ type DialogTitleSlots = {
171
+ /**
172
+ * By default this is a div.
173
+ */
174
+ root: Slot<'div', 'main'>;
175
+ };
176
+
177
+ type DialogTitleProps = ComponentProps<DialogTitleSlots>;
178
+ ```
179
+
180
+ ### DialogTitle
181
+
182
+ The DialogTitle component will expect to have a dialog title/header and will show the close (X icon) button if specified so. Apart from styling and presenting `closeButton`, this component does not have other behavior.
183
+
184
+ ```tsx
185
+ type DialogTitleSlots = {
186
+ /**
187
+ * By default this is a div, but can be a heading.
188
+ */
189
+ root: Slot<'div', 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6'>;
190
+ closeButton?: Slot<'button'>;
191
+ };
192
+
193
+ type DialogTitleProps = ComponentProps<DialogTitleSlots>;
194
+ ```
195
+
196
+ ### DialogBody
197
+
198
+ The `DialogBody` is a container where the content of the dialog is rendered. Apart from styling, this component does not have other behavior.
199
+
200
+ ```tsx
201
+ type DialogBodySlots = {
202
+ root: Slot<'div'>;
203
+ };
204
+
205
+ type DialogBodyProps = ComponentProps<DialogBodySlots>;
206
+ ```
207
+
208
+ ### DialogActions
209
+
210
+ `DialogActions` is a container for the actions of the dialog. Apart from styling, this component does not have other behavior.
211
+
212
+ ```tsx
213
+ type DialogActionsSlots = {
214
+ root: Slot<'div'>;
215
+ };
216
+
217
+ type DialogActionsProps = ComponentProps<DialogActionsSlots>;
218
+ ```
219
+
220
+ ## Sample Code
221
+
222
+ The below samples do not represent the definitive props of the final implemented component, but represent the ideal final implementations. Can be subject to change during the implementation phase.
223
+
224
+ ### Basic Dialog
225
+
226
+ ```tsx
227
+ const dialog = <Dialog>
228
+ <DialogTrigger>
229
+ <Button>Open Dialog</Button>
230
+ <DialogTrigger>
231
+ <DialogSurface>
232
+ This is as basic as it gets.
233
+ </DialogSurface>
234
+ </Dialog>
235
+ ```
236
+
237
+ ```html
238
+ <!-- expected DOM output -->
239
+ <button aria-haspopup="true" class="fui-button">Open Dialog</button>
240
+ <!-- ... portal ... -->
241
+ <div aria-hidden="true" class="fui-dialog-overlay"></div>
242
+ <div aria-modal="true" role="dialog" class="fui-dialog-content">This is as basic as it gets</div>
243
+ ```
244
+
245
+ ### Alert Dialog
246
+
247
+ An alert dialog is a modal dialog that interrupts the user's workflow to communicate an important message and acquire a response. Examples include action confirmation prompts and error message confirmations. The alertdialog role enables assistive technologies and browsers to distinguish alert dialogs from other dialogs so they have the option of giving alert dialogs special treatment, such as playing a system alert sound.
248
+
249
+ ```tsx
250
+ const dialog = <Dialog type="alert">
251
+ <DialogTrigger>
252
+ <Button>Open Dialog</Button>
253
+ <DialogTrigger>
254
+ <DialogSurface>
255
+ <DialogTitle>
256
+ This is an alert
257
+ </DialogTitle>
258
+ <DialogBody>
259
+ This is going to be inside the dialog
260
+ </DialogBody>
261
+ <DialogActions>
262
+ <DialogTrigger type="close">
263
+ <Button>Close</Button>
264
+ </DialogTrigger>
265
+ <Button>Action</Button>
266
+ </DialogActions>
267
+ </DialogSurface>
268
+ </Dialog>
269
+ ```
270
+
271
+ ```html
272
+ <button aria-haspopup="true" class="fui-button">Open Dialog</button>
273
+ <!-- ... portal ... -->
274
+ <div aria-hidden="true" class="fui-dialog-overlay"></div>
275
+ <div
276
+ aria-describedby="fui-dialog-body-id"
277
+ aria-labelledby="fui-dialog-title-id"
278
+ aria-modal="true"
279
+ role="alertdialog"
280
+ class="fui-dialog-content"
281
+ >
282
+ <div id="fui-dialog-title-id" class="fui-dialog-title">
283
+ <span>Title</span>
284
+ <!-- closeButton -->
285
+ </div>
286
+ <div id="fui-dialog-body-id" class="fui-dialog-body">This is going to be inside the dialog</div>
287
+ <div class="fui-dialog-actions">
288
+ <button class="fui-button">Close</button>
289
+ <button class="fui-button">Action</button>
290
+ </div>
291
+ </div>
292
+ <!-- ... portal ... -->
293
+ ```
294
+
295
+ ### Controlled Dialog
296
+
297
+ ```tsx
298
+ const CustomDialog = () => {
299
+ const [isOpen, setIsOpen] = React.useState(false);
300
+ const handleOpenChange = (ev, { open }) => setIsOpen(open);
301
+ const handleOpen = () => setIsOpen(true);
302
+ return (
303
+ <>
304
+ {/*
305
+ the trigger component is still useful outside of the Dialog,
306
+ to provide ARIA attributes, but it will no longer speak with the dialog.
307
+ A controlled state is required in this case
308
+ */}
309
+ <DialogTrigger>
310
+ <Button onClick={handleOpen}>Button outside Dialog Context</Button>
311
+ </DialogTrigger>
312
+ <Dialog open={isOpen} onOpenChange={handleOpenChange}>
313
+ <DialogSurface>
314
+ <DialogTitle>This is an alert</DialogTitle>
315
+ <DialogBody>This is going to be inside the dialog</DialogBody>
316
+ <DialogActions>
317
+ {/*
318
+ In this case the trigger can be used to request close through `onOpenChange`,
319
+ as it's inside Dialog context
320
+ */}
321
+ <DialogTrigger type="close">
322
+ <Button>Close</Button>
323
+ </DialogTrigger>
324
+ <Button>Action</Button>
325
+ </DialogActions>
326
+ </DialogSurface>
327
+ </Dialog>
328
+ </>
329
+ );
330
+ };
331
+ ```
332
+
333
+ ```html
334
+ <button aria-haspopup="true" class="fui-button">Open Dialog</button>
335
+ <!-- ... portal ... -->
336
+ <div aria-hidden="true" class="fui-dialog-overlay"></div>
337
+ <div
338
+ aria-describedby="fui-dialog-body-id"
339
+ aria-labelledby="fui-dialog-title-id"
340
+ aria-modal="true"
341
+ role="dialog"
342
+ class="fui-dialog-content"
343
+ >
344
+ <div id="fui-dialog-title-id" class="fui-dialog-title">
345
+ <span>Title</span>
346
+ <!-- closeButton -->
347
+ </div>
348
+ <div id="fui-dialog-body-id" class="fui-dialog-body">This is going to be inside the dialog</div>
349
+ <div class="fui-dialog-actions">
350
+ <button class="fui-button">Close</button>
351
+ <button class="fui-button">Action</button>
352
+ </div>
353
+ </div>
354
+ <!-- ... portal ... -->
355
+ ```
356
+
357
+ ### Async Input submission dialog
358
+
359
+ ```tsx
360
+ function AsyncConfirmDialog() {
361
+ const [input, setInput] = useState('');
362
+ const [state, sendInput] = useSendInput();
363
+ const [isOpen, setIsOpen] = useState(false);
364
+ const handleInputChange = ev => {
365
+ setInput(ev.target.value.trim());
366
+ };
367
+ const handleOpenChange = (ev, { open }) => {
368
+ setIsOpen(open);
369
+ setInput(''); // clean up on cancel/close
370
+ };
371
+ const handleSubmit = async ev => {
372
+ ev.preventDefault();
373
+ await sendInput(input); // sending data on confirm
374
+ setIsOpen(false);
375
+ };
376
+ return (
377
+ <>
378
+ <Dialog open={isOpen} onOpenChange={handleOpenChange}>
379
+ <DialogTrigger>
380
+ <Button>Open Dialog</Button>
381
+ </DialogTrigger>
382
+ <DialogSurface>
383
+ <DialogTitle>This is a dialog</DialogTitle>
384
+ <DialogBody>
385
+ <form id="form-id" onSubmit={handleSubmit}>
386
+ <Input required placeholder="Some input..." value={input} onChange={handleInputChange} />
387
+ </form>
388
+ </DialogBody>
389
+ <DialogActions>
390
+ <DialogTrigger type="close">
391
+ <Button>Close</Button>
392
+ </DialogTrigger>
393
+ <Button disabled={input === ''} form="form-id" type="submit">
394
+ {state === 'idle' && 'Submit'}
395
+ {state === 'submitting' && 'Submitting...'}
396
+ </Button>
397
+ </DialogActions>
398
+ </DialogSurface>
399
+ </Dialog>
400
+ </>
401
+ );
402
+ }
403
+ ```
404
+
405
+ ## Migration
406
+
407
+ _TBA: Link to migration guide doc_
408
+
409
+ ## Behaviors
410
+
411
+ Dialog will use **Tabster** to handle the keyboard navigation and ensure focus trapping.
412
+
413
+ The below references were used to decide appropriate keyboard interaction from an a11y perspective.
414
+
415
+ - https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/
416
+ - https://www.w3.org/WAI/ARIA/apg/example-index/dialog-modal/dialog.html
417
+ - https://www.w3.org/WAI/ARIA/apg/example-index/dialog-modal/alertdialog.html
418
+
419
+ ### Modal
420
+
421
+ #### Mouse & Touch
422
+
423
+ ![Mouse and touch behavior of Modal dialog](./assets/ModalDialogMouseInteraction.png)
424
+
425
+ 1. Clicking on the trigger (element / button component) a Dialog is displayed with a dimmed background.
426
+ 2. Clicking on the dimmed background dismisses the dialog.
427
+ 3. The dialog can be dismissed also when confirmation button is clicked (footer).
428
+
429
+ #### Keyboard
430
+
431
+ ![Keyboard behavior of a modal dialog](./assets/ModalDialogKeyboardInteraction.png)
432
+
433
+ 1. **(1)** TabKey to set focus on Trigger, use EnterKey to open.
434
+ 2. **(2-6)** Focus is moved to the first focusable control inside the dialog.
435
+ 3. **(5-6)** After the dialog is dismissed, keyboard focus should be moved back to where it was before it moved into the dialog. Otherwise the focus can be dropped to the beginning of the page. Or if the item is no longer available it can be moved to the next logical location in that region i.e. next / previous item.
436
+ 4. **TabKey** Moves focus to next focusable element inside the dialog. When focus is on the last focusable element in the dialog, moves focus to the next focusable action in the browser window.
437
+ 5. **Shift+Tab** Moves focus to previous focusable element inside the dialog. When focus is on the first focusable element in the dialog, moves focus to the last focusable action within the browser window.
438
+ 6. **EscKey** Closes the dialog, returning focus to the trigger, in case the trigger is gone or not possible to focus, the use might require to setup focus manually.
439
+
440
+ ### Non-Modal
441
+
442
+ #### Mouse & touch
443
+
444
+ ![Mouse and touch behavior of a non-modal dialog](./assets/NonModalDialogMouseInteraction.png)
445
+
446
+ 1. Clicking on the trigger (element / button component) a Dialog is displayed without a dimmed background.
447
+ 2. A user can continue to interact with elements on the page behind the dialog.
448
+ 3. Clicking the dismiss button (X icon in header), or cancel/dismiss buttons (footer) will close the dialog.
449
+
450
+ #### Keyboard
451
+
452
+ ![Keyboard behavior of non-modal dialog](./assets/NonModalDialogKeyboardInteraction.png)
453
+
454
+ 1. **(1)** **TabKey** to set focus on Trigger, use **EnterKey** to open.
455
+ 2. - **(2a)** Focus is moved to the default focusable control inside the dialog.
456
+ - **(2b)** **EnterKey** on dismiss action to close dialog,
457
+ 3. After the dialog is dismissed, keyboard focus should be moved back to where it was before it moved into the dialog. Otherwise the focus can be dropped to the beginning of the page.
458
+ 4. **TabKey** Moves focus to next focusable element inside the dialog, once you get to the end of the focusable items within the dialog focus moves to next actionable item outside of the dialog container.
459
+ 5. **Shift+Tab** Moves focus to previous focusable element inside the dialog and back to the trigger control.
460
+ 6. **EscKey** Closes the dialog when the focus is on the dialog.
461
+
462
+ ### Alert dialog
463
+
464
+ #### Mouse & Touch
465
+
466
+ ![Mouse and touch behavior of alert dialog](./assets/AlertDialogMouseInteraction.png)
467
+
468
+ 1. Clicking on the trigger (element / button component) a Dialog is displayed with a dimmed background.
469
+ 2. Windows under the dialog are are inert, their scrolling is blocked and clicking on the dimmed background will not close the dialog.
470
+ 3. Clicking the dismiss button (X icon in header), or cancel/dismiss buttons (footer) will dismiss the dialog.
471
+
472
+ #### Keyboard
473
+
474
+ ![Keyboard behavior of alert dialog](./assets/AlertDialogKeyboardInteraction.png)
475
+
476
+ 1. **(1)** **TabKey** to set focus on Trigger, use **EnterKey** to open.
477
+ 2. **(2 & 3)** Focus is automatically set to the first focusable element inside the dialog
478
+ 3. **EnterKey** Confirms or cancels the alert message and dialog is dismissed.
479
+ 4. **TabKey** Moves focus to next focusable element inside the dialog. When focus is on the last focusable element in the dialog, moves focus to the next focusable action in the browser window.
480
+ 5. **Shift+Tab** Moves focus to previous focusable element inside the dialog. When focus is on the first focusable element in the dialog, moves focus to the last focusable action within the browser window.
481
+
482
+ ## Accessibility
483
+
484
+ > ⚠️ _Note: All other accessibility information, not covered in this section, is provided throughout the spec._
485
+
486
+ The dialog component follows the [Dialog WAI-Aria design pattern](https://www.w3.org/WAI/ARIA/apg/patterns/dialogmodal/).
487
+
488
+ ### Aria roles and states
489
+
490
+ #### Modal
491
+
492
+ - Trigger button
493
+ - [`aria-haspopup="dialog"`](https://w3c.github.io/aria/#aria-haspopup)
494
+ - Dialog
495
+ - [`role="dialog"`](https://w3c.github.io/aria/#dialog)
496
+ - [`aria-modal=true`](https://w3c.github.io/aria/#aria-modal)
497
+ - [`aria-labelledby={dialog-title-idref}`](https://w3c.github.io/aria/#aria-labelledby)
498
+ - [`aria-describedby={dialog-body-idref}`](https://w3c.github.io/aria/#aria-describedby)
499
+
500
+ #### Non-modal
501
+
502
+ - Trigger button
503
+ - [`aria-haspopup="dialog"`](https://w3c.github.io/aria/#aria-haspopup)
504
+ - Dialog
505
+ - [`role="dialog"`](https://w3c.github.io/aria/#dialog)
506
+ - [`aria-modal=false`](https://w3c.github.io/aria/#aria-modal)
507
+ - [`aria-labelledby={dialog-title-idref}`](https://w3c.github.io/aria/#aria-labelledby)
508
+ - [`aria-describedby={dialog-body-idref}`](https://w3c.github.io/aria/#aria-describedby)
509
+
510
+ #### Alert dialog
511
+
512
+ - Trigger button
513
+ - [`aria-haspopup="dialog"`](https://w3c.github.io/aria/#aria-haspopup)
514
+ - Dialog
515
+ - [`role="alertdialog"`](https://w3c.github.io/aria/#dialog)
516
+ - [`aria-modal=true`](https://w3c.github.io/aria/#aria-modal)
517
+ - [`aria-labelledby={dialog-title-idref}`](https://w3c.github.io/aria/#aria-labelledby)
518
+ - [`aria-describedby={dialog-body-idref}`](https://w3c.github.io/aria/#aria-describedby)