@fluentui/react-dialog 9.0.0-beta.7 → 9.0.0-beta.8

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 (122) hide show
  1. package/CHANGELOG.json +154 -5
  2. package/CHANGELOG.md +34 -6
  3. package/Spec.md +44 -25
  4. package/dist/index.d.ts +59 -59
  5. package/lib/components/Dialog/Dialog.js +0 -2
  6. package/lib/components/Dialog/Dialog.js.map +1 -1
  7. package/lib/components/Dialog/Dialog.types.js.map +1 -1
  8. package/lib/components/Dialog/index.js +0 -1
  9. package/lib/components/Dialog/index.js.map +1 -1
  10. package/lib/components/Dialog/renderDialog.js +2 -10
  11. package/lib/components/Dialog/renderDialog.js.map +1 -1
  12. package/lib/components/Dialog/useDialog.js +19 -129
  13. package/lib/components/Dialog/useDialog.js.map +1 -1
  14. package/lib/components/Dialog/useDialogContextValues.js +4 -4
  15. package/lib/components/Dialog/useDialogContextValues.js.map +1 -1
  16. package/lib/components/DialogActions/useDialogActionsStyles.js +3 -5
  17. package/lib/components/DialogActions/useDialogActionsStyles.js.map +1 -1
  18. package/lib/components/DialogBody/useDialogBodyStyles.js +5 -5
  19. package/lib/components/DialogBody/useDialogBodyStyles.js.map +1 -1
  20. package/lib/components/DialogSurface/DialogSurface.types.js.map +1 -1
  21. package/lib/components/DialogSurface/renderDialogSurface.js +4 -2
  22. package/lib/components/DialogSurface/renderDialogSurface.js.map +1 -1
  23. package/lib/components/DialogSurface/useDialogSurface.js +120 -21
  24. package/lib/components/DialogSurface/useDialogSurface.js.map +1 -1
  25. package/lib/components/DialogSurface/useDialogSurfaceStyles.js +56 -7
  26. package/lib/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -1
  27. package/lib/components/DialogTitle/DialogTitle.js +2 -3
  28. package/lib/components/DialogTitle/DialogTitle.js.map +1 -1
  29. package/lib/components/DialogTitle/DialogTitle.types.js.map +1 -1
  30. package/lib/components/DialogTitle/renderDialogTitle.js +2 -5
  31. package/lib/components/DialogTitle/renderDialogTitle.js.map +1 -1
  32. package/lib/components/DialogTitle/useDialogTitle.js +15 -9
  33. package/lib/components/DialogTitle/useDialogTitle.js.map +1 -1
  34. package/lib/components/DialogTitle/useDialogTitleStyles.js +61 -54
  35. package/lib/components/DialogTitle/useDialogTitleStyles.js.map +1 -1
  36. package/lib/components/DialogTrigger/DialogTrigger.types.js.map +1 -1
  37. package/lib/components/DialogTrigger/useDialogTrigger.js +3 -22
  38. package/lib/components/DialogTrigger/useDialogTrigger.js.map +1 -1
  39. package/lib/contexts/constants.js +1 -1
  40. package/lib/contexts/constants.js.map +1 -1
  41. package/lib/contexts/dialogContext.js +2 -4
  42. package/lib/contexts/dialogContext.js.map +1 -1
  43. package/lib/index.js +1 -1
  44. package/lib/index.js.map +1 -1
  45. package/lib/utils/index.js +4 -3
  46. package/lib/utils/index.js.map +1 -1
  47. package/lib/utils/isEscapeKeyDown.js +5 -4
  48. package/lib/utils/isEscapeKeyDown.js.map +1 -1
  49. package/lib/utils/isHTMLDialogElement.js +4 -0
  50. package/lib/utils/isHTMLDialogElement.js.map +1 -0
  51. package/lib/utils/useControlNativeDialogOpenState.js +20 -0
  52. package/lib/utils/useControlNativeDialogOpenState.js.map +1 -0
  53. package/lib/utils/useDisableBodyScroll.js +60 -0
  54. package/lib/utils/useDisableBodyScroll.js.map +1 -0
  55. package/lib/utils/useFocusFirstElement.js +41 -0
  56. package/lib/utils/useFocusFirstElement.js.map +1 -0
  57. package/lib-commonjs/components/Dialog/Dialog.js +0 -3
  58. package/lib-commonjs/components/Dialog/Dialog.js.map +1 -1
  59. package/lib-commonjs/components/Dialog/index.js +0 -2
  60. package/lib-commonjs/components/Dialog/index.js.map +1 -1
  61. package/lib-commonjs/components/Dialog/renderDialog.js +2 -12
  62. package/lib-commonjs/components/Dialog/renderDialog.js.map +1 -1
  63. package/lib-commonjs/components/Dialog/useDialog.js +18 -128
  64. package/lib-commonjs/components/Dialog/useDialog.js.map +1 -1
  65. package/lib-commonjs/components/Dialog/useDialogContextValues.js +4 -4
  66. package/lib-commonjs/components/Dialog/useDialogContextValues.js.map +1 -1
  67. package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js +3 -6
  68. package/lib-commonjs/components/DialogActions/useDialogActionsStyles.js.map +1 -1
  69. package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js +4 -5
  70. package/lib-commonjs/components/DialogBody/useDialogBodyStyles.js.map +1 -1
  71. package/lib-commonjs/components/DialogSurface/renderDialogSurface.js +5 -2
  72. package/lib-commonjs/components/DialogSurface/renderDialogSurface.js.map +1 -1
  73. package/lib-commonjs/components/DialogSurface/useDialogSurface.js +120 -21
  74. package/lib-commonjs/components/DialogSurface/useDialogSurface.js.map +1 -1
  75. package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js +56 -6
  76. package/lib-commonjs/components/DialogSurface/useDialogSurfaceStyles.js.map +1 -1
  77. package/lib-commonjs/components/DialogTitle/DialogTitle.js +2 -3
  78. package/lib-commonjs/components/DialogTitle/DialogTitle.js.map +1 -1
  79. package/lib-commonjs/components/DialogTitle/renderDialogTitle.js +2 -6
  80. package/lib-commonjs/components/DialogTitle/renderDialogTitle.js.map +1 -1
  81. package/lib-commonjs/components/DialogTitle/useDialogTitle.js +18 -10
  82. package/lib-commonjs/components/DialogTitle/useDialogTitle.js.map +1 -1
  83. package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js +62 -56
  84. package/lib-commonjs/components/DialogTitle/useDialogTitleStyles.js.map +1 -1
  85. package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js +4 -24
  86. package/lib-commonjs/components/DialogTrigger/useDialogTrigger.js.map +1 -1
  87. package/lib-commonjs/contexts/constants.js +2 -2
  88. package/lib-commonjs/contexts/constants.js.map +1 -1
  89. package/lib-commonjs/contexts/dialogContext.js +2 -4
  90. package/lib-commonjs/contexts/dialogContext.js.map +1 -1
  91. package/lib-commonjs/index.js +1 -13
  92. package/lib-commonjs/index.js.map +1 -1
  93. package/lib-commonjs/utils/index.js +5 -3
  94. package/lib-commonjs/utils/index.js.map +1 -1
  95. package/lib-commonjs/utils/isEscapeKeyDown.js +5 -4
  96. package/lib-commonjs/utils/isEscapeKeyDown.js.map +1 -1
  97. package/lib-commonjs/utils/isHTMLDialogElement.js +13 -0
  98. package/lib-commonjs/utils/isHTMLDialogElement.js.map +1 -0
  99. package/lib-commonjs/utils/useControlNativeDialogOpenState.js +31 -0
  100. package/lib-commonjs/utils/useControlNativeDialogOpenState.js.map +1 -0
  101. package/lib-commonjs/utils/useDisableBodyScroll.js +73 -0
  102. package/lib-commonjs/utils/useDisableBodyScroll.js.map +1 -0
  103. package/lib-commonjs/utils/useFocusFirstElement.js +54 -0
  104. package/lib-commonjs/utils/useFocusFirstElement.js.map +1 -0
  105. package/package.json +13 -13
  106. package/dist/tsdoc-metadata.json +0 -11
  107. package/lib/components/Dialog/useDialogStyles.js +0 -41
  108. package/lib/components/Dialog/useDialogStyles.js.map +0 -1
  109. package/lib/utils/isTargetDisabled.js +0 -14
  110. package/lib/utils/isTargetDisabled.js.map +0 -1
  111. package/lib/utils/localShorthands.js +0 -9
  112. package/lib/utils/localShorthands.js.map +0 -1
  113. package/lib/utils/normalizeDefaultPrevented.js +0 -11
  114. package/lib/utils/normalizeDefaultPrevented.js.map +0 -1
  115. package/lib-commonjs/components/Dialog/useDialogStyles.js +0 -53
  116. package/lib-commonjs/components/Dialog/useDialogStyles.js.map +0 -1
  117. package/lib-commonjs/utils/isTargetDisabled.js +0 -23
  118. package/lib-commonjs/utils/isTargetDisabled.js.map +0 -1
  119. package/lib-commonjs/utils/localShorthands.js +0 -18
  120. package/lib-commonjs/utils/localShorthands.js.map +0 -1
  121. package/lib-commonjs/utils/normalizeDefaultPrevented.js +0 -20
  122. package/lib-commonjs/utils/normalizeDefaultPrevented.js.map +0 -1
@@ -2,5 +2,4 @@ export * from './Dialog';
2
2
  export * from './Dialog.types';
3
3
  export * from './renderDialog';
4
4
  export * from './useDialog';
5
- export * from './useDialogStyles';
6
5
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Dialog/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC","sourcesContent":["export * from './Dialog';\nexport * from './Dialog.types';\nexport * from './renderDialog';\nexport * from './useDialog';\nexport * from './useDialogStyles';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"../src/","sources":["components/Dialog/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC","sourcesContent":["export * from './Dialog';\nexport * from './Dialog.types';\nexport * from './renderDialog';\nexport * from './useDialog';\n"]}
@@ -1,6 +1,4 @@
1
1
  import * as React from 'react';
2
- import { getSlots } from '@fluentui/react-utilities';
3
- import { Portal } from '@fluentui/react-portal';
4
2
  import { DialogProvider, DialogSurfaceProvider } from '../../contexts';
5
3
  /**
6
4
  * Render the final JSX of Dialog
@@ -9,18 +7,12 @@ import { DialogProvider, DialogSurfaceProvider } from '../../contexts';
9
7
  export const renderDialog_unstable = (state, contextValues) => {
10
8
  const {
11
9
  content,
12
- trigger,
13
- open
10
+ trigger
14
11
  } = state;
15
- const {
16
- slots,
17
- slotProps
18
- } = getSlots(state);
19
12
  return /*#__PURE__*/React.createElement(DialogProvider, {
20
13
  value: contextValues.dialog
21
14
  }, /*#__PURE__*/React.createElement(DialogSurfaceProvider, {
22
15
  value: contextValues.dialogSurface
23
- }, trigger, open && /*#__PURE__*/React.createElement(Portal, null, slots.overlay && /*#__PURE__*/React.createElement(slots.overlay, { ...slotProps.overlay
24
- }), content)));
16
+ }, trigger, content));
25
17
  };
26
18
  //# sourceMappingURL=renderDialog.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Dialog/renderDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AACA,SAAS,MAAT,QAAuB,wBAAvB;AACA,SAAS,cAAT,EAAyB,qBAAzB,QAAsD,gBAAtD;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAG,CAAC,KAAD,EAAqB,aAArB,KAA2D;EAC9F,MAAM;IAAE,OAAF;IAAW,OAAX;IAAoB;EAApB,IAA6B,KAAnC;EACA,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAc,KAAd,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,cAAD,EAAe;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAf,eACE,KAAA,CAAA,aAAA,CAAC,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,EACG,OADH,EAEG,IAAI,iBACH,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO,IAAP,EACG,KAAK,CAAC,OAAN,iBAAiB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,OAAP,EAAc,EAAA,GAAK,SAAS,CAAC;EAAf,CAAd,CADpB,EAEG,OAFH,CAHJ,CADF,CADF;AAaD,CAjBM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport { Portal } from '@fluentui/react-portal';\nimport { DialogProvider, DialogSurfaceProvider } from '../../contexts';\nimport type { DialogState, DialogSlots, DialogContextValues } from './Dialog.types';\n\n/**\n * Render the final JSX of Dialog\n */\nexport const renderDialog_unstable = (state: DialogState, contextValues: DialogContextValues) => {\n const { content, trigger, open } = state;\n const { slots, slotProps } = getSlots<DialogSlots>(state);\n\n return (\n <DialogProvider value={contextValues.dialog}>\n <DialogSurfaceProvider value={contextValues.dialogSurface}>\n {trigger}\n {open && (\n <Portal>\n {slots.overlay && <slots.overlay {...slotProps.overlay} />}\n {content}\n </Portal>\n )}\n </DialogSurfaceProvider>\n </DialogProvider>\n );\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/Dialog/renderDialog.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,cAAT,EAAyB,qBAAzB,QAAsD,gBAAtD;AAGA;;AAEG;;AACH,OAAO,MAAM,qBAAqB,GAAG,CAAC,KAAD,EAAqB,aAArB,KAA2D;EAC9F,MAAM;IAAE,OAAF;IAAW;EAAX,IAAuB,KAA7B;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,cAAD,EAAe;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAf,eACE,KAAA,CAAA,aAAA,CAAC,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,EACG,OADH,EAEG,OAFH,CADF,CADF;AAQD,CAXM","sourcesContent":["import * as React from 'react';\nimport { DialogProvider, DialogSurfaceProvider } from '../../contexts';\nimport type { DialogState, DialogContextValues } from './Dialog.types';\n\n/**\n * Render the final JSX of Dialog\n */\nexport const renderDialog_unstable = (state: DialogState, contextValues: DialogContextValues) => {\n const { content, trigger } = state;\n\n return (\n <DialogProvider value={contextValues.dialog}>\n <DialogSurfaceProvider value={contextValues.dialogSurface}>\n {trigger}\n {content}\n </DialogSurfaceProvider>\n </DialogProvider>\n );\n};\n"],"sourceRoot":"../src/"}
@@ -1,8 +1,8 @@
1
1
  import * as React from 'react';
2
- import { resolveShorthand, useControllableState, useEventCallback, useId } from '@fluentui/react-utilities';
3
- import { useFocusFinders } from '@fluentui/react-tabster';
4
- import { useFluent_unstable } from '@fluentui/react-shared-contexts';
5
- import { normalizeDefaultPrevented, isEscapeKeyDismiss } from '../../utils';
2
+ import { useControllableState, useEventCallback, useId, useIsomorphicLayoutEffect, useMergedRefs } from '@fluentui/react-utilities';
3
+ import { useHasParentContext } from '@fluentui/react-context-selector';
4
+ import { useControlNativeDialogOpenState, useDisableBodyScroll, useFocusFirstElement } from '../../utils';
5
+ import { DialogContext } from '../../contexts';
6
6
  /**
7
7
  * Create the state required to render Dialog.
8
8
  *
@@ -15,7 +15,6 @@ import { normalizeDefaultPrevented, isEscapeKeyDismiss } from '../../utils';
15
15
  export const useDialog_unstable = props => {
16
16
  const {
17
17
  children,
18
- overlay,
19
18
  modalType = 'modal',
20
19
  onOpenChange
21
20
  } = props;
@@ -25,63 +24,36 @@ export const useDialog_unstable = props => {
25
24
  defaultState: props.defaultOpen,
26
25
  initialState: false
27
26
  });
28
- const overlayShorthand = resolveShorthand(overlay, {
29
- required: modalType !== 'non-modal',
30
- defaultProps: {
31
- 'aria-hidden': 'true'
32
- }
33
- });
34
27
  const requestOpenChange = useEventCallback(data => {
35
- const isDefaultPrevented = normalizeDefaultPrevented(data.event);
36
-
37
- if (onOpenChange) {
38
- onOpenChange(data.event, data);
39
- } // if user prevents default then do not change state value
28
+ onOpenChange === null || onOpenChange === void 0 ? void 0 : onOpenChange(data.event, data); // if user prevents default then do not change state value
40
29
  // otherwise updates state value and trigger reference to the element that caused the opening
41
30
 
42
-
43
- if (!isDefaultPrevented()) {
44
- triggerRef.current = !open && data.open ? data.event.currentTarget : null;
31
+ if (!data.event.isDefaultPrevented()) {
45
32
  setOpen(data.open);
46
33
  }
47
34
  });
48
- const {
49
- contentRef,
50
- triggerRef
51
- } = useFocusFirstElement({
52
- open,
53
- modalType,
54
- requestOpenChange
55
- });
56
- const handleOverLayClick = useEventCallback(event => {
57
- var _a;
58
-
59
- (_a = overlayShorthand === null || overlayShorthand === void 0 ? void 0 : overlayShorthand.onClick) === null || _a === void 0 ? void 0 : _a.call(overlayShorthand, event);
60
-
61
- if (isOverlayClickDismiss(event, modalType)) {
62
- requestOpenChange({
63
- event,
64
- open: false,
65
- type: 'overlayClick'
66
- });
35
+ const focusRef = useFocusFirstElement(open, modalType);
36
+ const nativeControlRef = useControlNativeDialogOpenState(open, modalType);
37
+ const disableBodyScroll = useDisableBodyScroll();
38
+ const isBodyScrollLocked = Boolean(open && modalType !== 'non-modal');
39
+ useIsomorphicLayoutEffect(() => {
40
+ if (isBodyScrollLocked) {
41
+ return disableBodyScroll();
67
42
  }
68
- });
43
+ }, [disableBodyScroll, isBodyScrollLocked]);
69
44
  return {
70
45
  components: {
71
- overlay: 'div'
72
- },
73
- overlay: overlayShorthand && { ...overlayShorthand,
74
- onClick: handleOverLayClick
46
+ backdrop: 'div'
75
47
  },
76
48
  open,
77
49
  modalType,
78
- content,
50
+ content: open ? content : null,
79
51
  trigger,
80
- triggerRef,
81
- contentRef,
82
52
  requestOpenChange,
83
53
  dialogBodyID: useId('dialog-body-'),
84
- dialogTitleID: useId('dialog-title-')
54
+ dialogTitleID: useId('dialog-title-'),
55
+ isNestedDialog: useHasParentContext(DialogContext),
56
+ dialogRef: useMergedRefs(focusRef, nativeControlRef)
85
57
  };
86
58
  };
87
59
  /**
@@ -112,86 +84,4 @@ function childrenToTriggerAndContent(children) {
112
84
  return [undefined, undefined];
113
85
  }
114
86
  }
115
- /**
116
- * Checks is click event is a proper Overlay click dismiss
117
- */
118
-
119
-
120
- function isOverlayClickDismiss(event, type) {
121
- const isDefaultPrevented = normalizeDefaultPrevented(event);
122
- return type === 'modal' && !isDefaultPrevented();
123
- }
124
- /**
125
- * Focus first element on content when dialog is opened,
126
- * in case there's no focusable element, then a eventlistener is added to document
127
- * to ensure Escape keydown functionality
128
- */
129
-
130
-
131
- function useFocusFirstElement({
132
- open,
133
- requestOpenChange,
134
- modalType
135
- }) {
136
- const {
137
- findFirstFocusable
138
- } = useFocusFinders();
139
- const {
140
- targetDocument
141
- } = useFluent_unstable();
142
- const contentRef = React.useRef(null);
143
- const triggerRef = React.useRef(null);
144
- React.useEffect(() => {
145
- if (!open) {
146
- return;
147
- }
148
-
149
- const element = contentRef.current && findFirstFocusable(contentRef.current);
150
-
151
- if (element) {
152
- element.focus(); // NOTE: if it's non-modal global listener to escape is necessary
153
-
154
- if (modalType !== 'non-modal') {
155
- return;
156
- }
157
- } else {
158
- if (process.env.NODE_ENV !== 'production') {
159
- // eslint-disable-next-line no-console
160
- console.warn('A Dialog should have at least one focusable element inside DialogSurface');
161
- }
162
- }
163
-
164
- if (triggerRef.current && targetDocument) {
165
- const trigger = triggerRef.current; // if the trigger is still the active element, the default behavior is to return focus to document.body,
166
- // which can be achived by blurring
167
-
168
- if (targetDocument.activeElement === trigger) {
169
- trigger.blur();
170
- }
171
-
172
- const listener = event => {
173
- if (isEscapeKeyDismiss(event, modalType)) {
174
- requestOpenChange({
175
- event,
176
- open: false,
177
- type: 'documentEscapeKeyDown'
178
- });
179
- trigger.focus();
180
- event.stopImmediatePropagation();
181
- }
182
- };
183
-
184
- targetDocument.addEventListener('keydown', listener, {
185
- passive: false
186
- });
187
- return () => {
188
- targetDocument.removeEventListener('keydown', listener);
189
- };
190
- }
191
- }, [findFirstFocusable, requestOpenChange, open, modalType, targetDocument]);
192
- return {
193
- contentRef,
194
- triggerRef
195
- };
196
- }
197
87
  //# sourceMappingURL=useDialog.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Dialog/useDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,gBAAT,EAA2B,oBAA3B,EAAiD,gBAAjD,EAAmE,KAAnE,QAAgF,2BAAhF;AACA,SAAS,eAAT,QAAgC,yBAAhC;AACA,SAAS,kBAAT,QAAmC,iCAAnC;AACA,SAAS,yBAAT,EAAoC,kBAApC,QAA8D,aAA9D;AAIA;;;;;;;AAOG;;AACH,OAAO,MAAM,kBAAkB,GAAI,KAAD,IAAoC;EACpE,MAAM;IAAE,QAAF;IAAY,OAAZ;IAAqB,SAAS,GAAG,OAAjC;IAA0C;EAA1C,IAA2D,KAAjE;EAEA,MAAM,CAAC,OAAD,EAAU,OAAV,IAAqB,2BAA2B,CAAC,QAAD,CAAtD;EAEA,MAAM,CAAC,IAAD,EAAO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;MACA,OAAO,MAAK;QACV,cAAc,CAAC,mBAAf,CAAmC,SAAnC,EAA8C,QAA9C;MACD,CAFD;IAGD;EACF,CA1CD,EA0CG,CAAC,kBAAD,EAAqB,iBAArB,EAAwC,IAAxC,EAA8C,SAA9C,EAAyD,cAAzD,CA1CH;EA4CA,OAAO;IAAE,UAAF;IAAc;EAAd,CAAP;AACD","sourcesContent":["import * as React from 'react';\nimport { resolveShorthand, useControllableState, useEventCallback, useId } from '@fluentui/react-utilities';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { normalizeDefaultPrevented, isEscapeKeyDismiss } from '../../utils';\n\nimport type { DialogProps, DialogState, DialogModalType, DialogOpenChangeData } from './Dialog.types';\n\n/**\n * Create the state required to render Dialog.\n *\n * The returned state can be modified with hooks such as useDialogStyles_unstable,\n * before being passed to renderDialog_unstable.\n *\n * @param props - props from this instance of Dialog\n */\nexport const useDialog_unstable = (props: DialogProps): DialogState => {\n const { children, overlay, modalType = 'modal', onOpenChange } = props;\n\n const [trigger, content] = childrenToTriggerAndContent(children);\n\n const [open, setOpen] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const overlayShorthand = resolveShorthand(overlay, {\n required: modalType !== 'non-modal',\n defaultProps: {\n 'aria-hidden': 'true',\n },\n });\n\n const requestOpenChange = useEventCallback((data: DialogOpenChangeData) => {\n const isDefaultPrevented = normalizeDefaultPrevented(data.event);\n\n if (onOpenChange) {\n onOpenChange(data.event, data);\n }\n\n // if user prevents default then do not change state value\n // otherwise updates state value and trigger reference to the element that caused the opening\n if (!isDefaultPrevented()) {\n (triggerRef as React.MutableRefObject<HTMLElement | null>).current =\n !open && data.open ? (data.event.currentTarget as HTMLElement) : null;\n setOpen(data.open);\n }\n });\n\n const { contentRef, triggerRef } = useFocusFirstElement({\n open,\n modalType,\n requestOpenChange,\n });\n\n const handleOverLayClick = useEventCallback((event: React.MouseEvent<HTMLDivElement>) => {\n overlayShorthand?.onClick?.(event);\n if (isOverlayClickDismiss(event, modalType)) {\n requestOpenChange({ event, open: false, type: 'overlayClick' });\n }\n });\n\n return {\n components: {\n overlay: 'div',\n },\n overlay: overlayShorthand && {\n ...overlayShorthand,\n onClick: handleOverLayClick,\n },\n open,\n modalType,\n content,\n trigger,\n triggerRef,\n contentRef,\n requestOpenChange,\n dialogBodyID: useId('dialog-body-'),\n dialogTitleID: useId('dialog-title-'),\n };\n};\n\n/**\n * Extracts trigger and content from children\n */\nfunction childrenToTriggerAndContent(\n children: React.ReactNode,\n): readonly [trigger: React.ReactNode, content: React.ReactNode] {\n const childrenArray = React.Children.toArray(children) as React.ReactElement[];\n if (process.env.NODE_ENV !== 'production') {\n if (childrenArray.length !== 1 && childrenArray.length !== 2) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Dialog must contain at least one child <DialogSurface/>,\\n' +\n 'and at most two children <DialogTrigger/> <DialogSurface/> (in this order)',\n );\n }\n }\n switch (childrenArray.length) {\n // case where there's a trigger followed by content\n case 2:\n return childrenArray as [trigger: React.ReactNode, content: React.ReactNode];\n // case where there's only content\n case 1:\n return [undefined, childrenArray[0]];\n // unknown case\n default:\n return [undefined, undefined];\n }\n}\n\n/**\n * Checks is click event is a proper Overlay click dismiss\n */\nfunction isOverlayClickDismiss(event: React.MouseEvent, type: DialogModalType): boolean {\n const isDefaultPrevented = normalizeDefaultPrevented(event);\n return type === 'modal' && !isDefaultPrevented();\n}\n\n/**\n * Focus first element on content when dialog is opened,\n * in case there's no focusable element, then a eventlistener is added to document\n * to ensure Escape keydown functionality\n */\nfunction useFocusFirstElement({\n open,\n requestOpenChange,\n modalType,\n}: Pick<DialogState, 'open' | 'requestOpenChange' | 'modalType'>) {\n const { findFirstFocusable } = useFocusFinders();\n const { targetDocument } = useFluent_unstable();\n const contentRef = React.useRef<HTMLElement>(null);\n const triggerRef = React.useRef<HTMLElement>(null);\n\n React.useEffect(() => {\n if (!open) {\n return;\n }\n\n const element = contentRef.current && findFirstFocusable(contentRef.current);\n if (element) {\n element.focus();\n // NOTE: if it's non-modal global listener to escape is necessary\n if (modalType !== 'non-modal') {\n return;\n }\n } else {\n if (process.env.NODE_ENV !== 'production') {\n // eslint-disable-next-line no-console\n console.warn('A Dialog should have at least one focusable element inside DialogSurface');\n }\n }\n\n if (triggerRef.current && targetDocument) {\n const trigger = triggerRef.current;\n // if the trigger is still the active element, the default behavior is to return focus to document.body,\n // which can be achived by blurring\n if (targetDocument.activeElement === trigger) {\n trigger.blur();\n }\n const listener = (event: KeyboardEvent) => {\n if (isEscapeKeyDismiss(event, modalType)) {\n requestOpenChange({\n event,\n open: false,\n type: 'documentEscapeKeyDown',\n });\n trigger.focus();\n event.stopImmediatePropagation();\n }\n };\n targetDocument.addEventListener('keydown', listener, { passive: false });\n return () => {\n targetDocument.removeEventListener('keydown', listener);\n };\n }\n }, [findFirstFocusable, requestOpenChange, open, modalType, targetDocument]);\n\n return { contentRef, triggerRef };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/Dialog/useDialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SACE,oBADF,EAEE,gBAFF,EAGE,KAHF,EAIE,yBAJF,EAKE,aALF,QAMO,2BANP;AAOA,SAAS,mBAAT,QAAoC,kCAApC;AACA,SAAS,+BAAT,EAA0C,oBAA1C,EAAgE,oBAAhE,QAA4F,aAA5F;AACA,SAAS,aAAT,QAA8B,gBAA9B;AAIA;;;;;;;AAOG;;AACH,OAAO,MAAM,kBAAkB,GAAI,KAAD,IAAoC;EACpE,MAAM;IAAE,QAAF;IAAY,SAAS,GAAG,OAAxB;IAAiC;EAAjC,IAAkD,KAAxD;EAEA,MAAM,CAAC,OAAD,EAAU,OAAV,IAAqB,2BAA2B,CAAC,QAAD,CAAtD;EAEA,MAAM,CAAC,IAAD,EAAO,OAAP,IAAkB,oBAAoB,CAAC;IAC3C,KAAK,EAAE,KAAK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M,aAAa,GAAG,KAAK,CAAC,QAAN,CAAe,OAAf,CAAuB,QAAvB,CAAtB;;EACA,IAAI,OAAO,CAAC,GAAR,CAAY,QAAZ,KAAyB,YAA7B,EAA2C;IACzC,IAAI,aAAa,CAAC,MAAd,KAAyB,CAAzB,IAA8B,aAAa,CAAC,MAAd,KAAyB,CAA3D,EAA8D;MAC5D;MACA,OAAO,CAAC,IAAR,CACE,+DACE,4EAFJ;IAID;EACF;;EACD,QAAQ,aAAa,CAAC,MAAtB;IACE;IACA,KAAK,CAAL;MACE,OAAO,aAAP;IACF;;IACA,KAAK,CAAL;MACE,OAAO,CAAC,SAAD,EAAY,aAAa,CAAC,CAAD,CAAzB,CAAP;IACF;;IACA;MACE,OAAO,CAAC,SAAD,EAAY,SAAZ,CAAP;EATJ;AAWD","sourcesContent":["import * as React from 'react';\nimport {\n useControllableState,\n useEventCallback,\n useId,\n useIsomorphicLayoutEffect,\n useMergedRefs,\n} from '@fluentui/react-utilities';\nimport { useHasParentContext } from '@fluentui/react-context-selector';\nimport { useControlNativeDialogOpenState, useDisableBodyScroll, useFocusFirstElement } from '../../utils';\nimport { DialogContext } from '../../contexts';\n\nimport type { DialogOpenChangeData, DialogProps, DialogState } from './Dialog.types';\n\n/**\n * Create the state required to render Dialog.\n *\n * The returned state can be modified with hooks such as useDialogStyles_unstable,\n * before being passed to renderDialog_unstable.\n *\n * @param props - props from this instance of Dialog\n */\nexport const useDialog_unstable = (props: DialogProps): DialogState => {\n const { children, modalType = 'modal', onOpenChange } = props;\n\n const [trigger, content] = childrenToTriggerAndContent(children);\n\n const [open, setOpen] = useControllableState({\n state: props.open,\n defaultState: props.defaultOpen,\n initialState: false,\n });\n\n const requestOpenChange = useEventCallback((data: DialogOpenChangeData) => {\n onOpenChange?.(data.event, data);\n\n // if user prevents default then do not change state value\n // otherwise updates state value and trigger reference to the element that caused the opening\n if (!data.event.isDefaultPrevented()) {\n setOpen(data.open);\n }\n });\n\n const focusRef = useFocusFirstElement(open, modalType);\n const nativeControlRef = useControlNativeDialogOpenState(open, modalType);\n const disableBodyScroll = useDisableBodyScroll();\n const isBodyScrollLocked = Boolean(open && modalType !== 'non-modal');\n\n useIsomorphicLayoutEffect(() => {\n if (isBodyScrollLocked) {\n return disableBodyScroll();\n }\n }, [disableBodyScroll, isBodyScrollLocked]);\n\n return {\n components: {\n backdrop: 'div',\n },\n open,\n modalType,\n content: open ? content : null,\n trigger,\n requestOpenChange,\n dialogBodyID: useId('dialog-body-'),\n dialogTitleID: useId('dialog-title-'),\n isNestedDialog: useHasParentContext(DialogContext),\n dialogRef: useMergedRefs(focusRef, nativeControlRef),\n };\n};\n\n/**\n * Extracts trigger and content from children\n */\nfunction childrenToTriggerAndContent(\n children: React.ReactNode,\n): readonly [trigger: React.ReactNode, content: React.ReactNode] {\n const childrenArray = React.Children.toArray(children) as React.ReactElement[];\n if (process.env.NODE_ENV !== 'production') {\n if (childrenArray.length !== 1 && childrenArray.length !== 2) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Dialog must contain at least one child <DialogSurface/>,\\n' +\n 'and at most two children <DialogTrigger/> <DialogSurface/> (in this order)',\n );\n }\n }\n switch (childrenArray.length) {\n // case where there's a trigger followed by content\n case 2:\n return childrenArray as [trigger: React.ReactNode, content: React.ReactNode];\n // case where there's only content\n case 1:\n return [undefined, childrenArray[0]];\n // unknown case\n default:\n return [undefined, undefined];\n }\n}\n"],"sourceRoot":"../src/"}
@@ -2,10 +2,10 @@ export function useDialogContextValues_unstable(state) {
2
2
  const {
3
3
  modalType,
4
4
  open,
5
- triggerRef,
6
- contentRef,
7
5
  dialogBodyID,
6
+ dialogRef,
8
7
  dialogTitleID,
8
+ isNestedDialog,
9
9
  requestOpenChange
10
10
  } = state;
11
11
  /**
@@ -16,10 +16,10 @@ export function useDialogContextValues_unstable(state) {
16
16
  const dialog = {
17
17
  open,
18
18
  modalType,
19
- triggerRef,
20
- contentRef,
19
+ dialogRef,
21
20
  dialogBodyID,
22
21
  dialogTitleID,
22
+ isNestedDialog,
23
23
  requestOpenChange
24
24
  };
25
25
  const dialogSurface = false;
@@ -1 +1 @@
1
- {"version":3,"sources":["components/Dialog/useDialogContextValues.ts"],"names":[],"mappings":"AAGA,OAAM,SAAU,+BAAV,CAA0C,KAA1C,EAA4D;EAChE,MAAM;IAAE,SAAF;IAAa,IAAb;IAAmB,UAAnB;IAA+B,UAA/B;IAA2C,YAA3C;IAAyD,aAAzD;IAAwE;EAAxE,IAA8F,KAApG;EAEA;;;AAGG;;EACH,MAAM,MAAM,GAAuB;IACjC,IADiC;IAEjC,SAFiC;IAGjC,UAHiC;IAIjC,UAJiC;IAKjC,YALiC;IAMjC,aANiC;IAOjC;EAPiC,CAAnC;EAUA,MAAM,aAAa,GAA8B,KAAjD;EAEA,OAAO;IAAE,MAAF;IAAU;EAAV,CAAP;AACD","sourcesContent":["import type { DialogContextValue, DialogSurfaceContextValue } from '../../contexts';\nimport type { DialogContextValues, DialogState } from './Dialog.types';\n\nexport function useDialogContextValues_unstable(state: DialogState): DialogContextValues {\n const { modalType, open, triggerRef, contentRef, dialogBodyID, dialogTitleID, requestOpenChange } = state;\n\n /**\n * This context is created with \"@fluentui/react-context-selector\",\n * there is no sense to memoize it\n */\n const dialog: DialogContextValue = {\n open,\n modalType,\n triggerRef,\n contentRef,\n dialogBodyID,\n dialogTitleID,\n requestOpenChange,\n };\n\n const dialogSurface: DialogSurfaceContextValue = false;\n\n return { dialog, dialogSurface };\n}\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/Dialog/useDialogContextValues.ts"],"names":[],"mappings":"AAGA,OAAM,SAAU,+BAAV,CAA0C,KAA1C,EAA4D;EAChE,MAAM;IAAE,SAAF;IAAa,IAAb;IAAmB,YAAnB;IAAiC,SAAjC;IAA4C,aAA5C;IAA2D,cAA3D;IAA2E;EAA3E,IAAiG,KAAvG;EAEA;;;AAGG;;EACH,MAAM,MAAM,GAAuB;IACjC,IADiC;IAEjC,SAFiC;IAGjC,SAHiC;IAIjC,YAJiC;IAKjC,aALiC;IAMjC,cANiC;IAOjC;EAPiC,CAAnC;EAUA,MAAM,aAAa,GAA8B,KAAjD;EAEA,OAAO;IAAE,MAAF;IAAU;EAAV,CAAP;AACD","sourcesContent":["import type { DialogContextValue, DialogSurfaceContextValue } from '../../contexts';\nimport type { DialogContextValues, DialogState } from './Dialog.types';\n\nexport function useDialogContextValues_unstable(state: DialogState): DialogContextValues {\n const { modalType, open, dialogBodyID, dialogRef, dialogTitleID, isNestedDialog, requestOpenChange } = state;\n\n /**\n * This context is created with \"@fluentui/react-context-selector\",\n * there is no sense to memoize it\n */\n const dialog: DialogContextValue = {\n open,\n modalType,\n dialogRef,\n dialogBodyID,\n dialogTitleID,\n isNestedDialog,\n requestOpenChange,\n };\n\n const dialogSurface: DialogSurfaceContextValue = false;\n\n return { dialog, dialogSurface };\n}\n"],"sourceRoot":"../src/"}
@@ -1,6 +1,5 @@
1
1
  import { __styles, mergeClasses, shorthands } from '@griffel/react';
2
2
  import { DIALOG_GAP, ACTIONS_END_GRID_AREA, ACTIONS_START_GRID_AREA, MEDIA_QUERY_BREAKPOINT_SELECTOR } from '../../contexts/constants';
3
- import * as localShorthands from '../../utils/localShorthands';
4
3
  export const dialogActionsClassNames = {
5
4
  root: 'fui-DialogActions'
6
5
  };
@@ -12,26 +11,25 @@ const useStyles = /*#__PURE__*/__styles({
12
11
  "mc9l5x": "f22iagw",
13
12
  "i8kkvl": "f4px1ci",
14
13
  "Belr9w4": "fn67r4l",
15
- "Bnr8eeb": "f12ep7o",
16
14
  "Bmdcpmo": "f6glcwc",
17
15
  "th9wkt": "f1e3st1r"
18
16
  },
19
17
  "gridPositionEnd": {
20
18
  "Bdqf98w": "f1a7i8kp",
21
19
  "Ijaq50": "f11u0jfc",
22
- "nk6f5a": "f23awfp",
23
20
  "Br312pm": "f1d6tb1o",
21
+ "nk6f5a": "f23awfp",
24
22
  "Bw0ie65": "fiappcv"
25
23
  },
26
24
  "gridPositionStart": {
27
25
  "Bdqf98w": "fsxvdwy",
28
26
  "Ijaq50": "f1vnb230",
29
- "nk6f5a": "f13d374e",
30
27
  "Br312pm": "f14781pt",
28
+ "nk6f5a": "f13d374e",
31
29
  "Bw0ie65": "f1fjo411"
32
30
  }
33
31
  }, {
34
- "d": [".f3052tw{height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;}", ".f1ewtqcl{box-sizing:border-box;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f4px1ci{-webkit-column-gap:8px;column-gap:8px;}", ".fn67r4l{row-gap:8px;}", ".f12ep7o>.fui-Button{max-width:100%;}", ".f1a7i8kp{justify-self:end;}", ".f11u0jfc{grid-row-start:actions-end;}", ".f23awfp{grid-row-end:actions-end;}", ".f1d6tb1o{grid-column-start:actions-end;}", ".fiappcv{grid-column-end:actions-end;}", ".fsxvdwy{justify-self:start;}", ".f1vnb230{grid-row-start:actions-start;}", ".f13d374e{grid-row-end:actions-start;}", ".f14781pt{grid-column-start:actions-start;}", ".f1fjo411{grid-column-end:actions-start;}"],
32
+ "d": [".f3052tw{height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;}", ".f1ewtqcl{box-sizing:border-box;}", ".f22iagw{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;}", ".f4px1ci{-webkit-column-gap:8px;column-gap:8px;}", ".fn67r4l{row-gap:8px;}", ".f1a7i8kp{justify-self:end;}", ".f11u0jfc{grid-row-start:actions-end;}", ".f1d6tb1o{grid-column-start:actions-end;}", ".f23awfp{grid-row-end:actions-end;}", ".fiappcv{grid-column-end:actions-end;}", ".fsxvdwy{justify-self:start;}", ".f1vnb230{grid-row-start:actions-start;}", ".f14781pt{grid-column-start:actions-start;}", ".f13d374e{grid-row-end:actions-start;}", ".f1fjo411{grid-column-end:actions-start;}"],
35
33
  "m": [["@media screen and (max-width: 480px){.f6glcwc{-webkit-flex-direction:column;-ms-flex-direction:column;flex-direction:column;}}", {
36
34
  "m": "screen and (max-width: 480px)"
37
35
  }], ["@media screen and (max-width: 480px){.f1e3st1r{justify-self:stretch;}}", {
@@ -1 +1 @@
1
- {"version":3,"sources":["components/DialogActions/useDialogActionsStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAGA,SACE,UADF,EAEE,qBAFF,EAGE,uBAHF,EAIE,+BAJF,QAKO,0BALP;AAMA,OAAO,KAAK,eAAZ,MAAiC,6BAAjC;AAEA,OAAO,MAAM,uBAAuB,GAAuC;EACzE,IAAI,EAAE;AADmE,CAApE;;AAIP,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;EAAA;IAAA;EAAA;IAAA;EAAA;AAAA,EAAlB;AAwBA;;AAEG;;;AACH,OAAO,MAAM,+BAA+B,GAAI,KAAD,IAAkD;EAC/F,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CACjC,uBAAuB,CAAC,IADS,EAEjC,MAAM,CAAC,IAF0B,EAGjC,KAAK,CAAC,QAAN,KAAmB,OAAnB,IAA8B,MAAM,CAAC,iBAHJ,EAIjC,KAAK,CAAC,QAAN,KAAmB,KAAnB,IAA4B,MAAM,CAAC,eAJF,EAKjC,KAAK,CAAC,IAAN,CAAW,SALsB,CAAnC;EAOA,OAAO,KAAP;AACD,CAVM","sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { DialogActionsSlots, DialogActionsState } from './DialogActions.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport {\n DIALOG_GAP,\n ACTIONS_END_GRID_AREA,\n ACTIONS_START_GRID_AREA,\n MEDIA_QUERY_BREAKPOINT_SELECTOR,\n} from '../../contexts/constants';\nimport * as localShorthands from '../../utils/localShorthands';\n\nexport const dialogActionsClassNames: SlotClassNames<DialogActionsSlots> = {\n root: 'fui-DialogActions',\n};\n\nconst useStyles = makeStyles({\n root: {\n height: 'fit-content',\n boxSizing: 'border-box',\n display: 'flex',\n ...shorthands.gap(DIALOG_GAP),\n '> .fui-Button': {\n maxWidth: '100%',\n },\n [MEDIA_QUERY_BREAKPOINT_SELECTOR]: {\n flexDirection: 'column',\n justifySelf: 'stretch',\n },\n },\n gridPositionEnd: {\n justifySelf: 'end',\n ...localShorthands.gridArea(ACTIONS_END_GRID_AREA),\n },\n gridPositionStart: {\n justifySelf: 'start',\n ...localShorthands.gridArea(ACTIONS_START_GRID_AREA),\n },\n});\n\n/**\n * Apply styling to the DialogActions slots based on the state\n */\nexport const useDialogActionsStyles_unstable = (state: DialogActionsState): DialogActionsState => {\n const styles = useStyles();\n state.root.className = mergeClasses(\n dialogActionsClassNames.root,\n styles.root,\n state.position === 'start' && styles.gridPositionStart,\n state.position === 'end' && styles.gridPositionEnd,\n state.root.className,\n );\n return state;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/DialogActions/useDialogActionsStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAGA,SACE,UADF,EAEE,qBAFF,EAGE,uBAHF,EAIE,+BAJF,QAKO,0BALP;AAOA,OAAO,MAAM,uBAAuB,GAAuC;EACzE,IAAI,EAAE;AADmE,CAApE;;AAIP,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;EAAA;IAAA;EAAA;IAAA;EAAA;AAAA,EAAlB;AAqBA;;AAEG;;;AACH,OAAO,MAAM,+BAA+B,GAAI,KAAD,IAAkD;EAC/F,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CACjC,uBAAuB,CAAC,IADS,EAEjC,MAAM,CAAC,IAF0B,EAGjC,KAAK,CAAC,QAAN,KAAmB,OAAnB,IAA8B,MAAM,CAAC,iBAHJ,EAIjC,KAAK,CAAC,QAAN,KAAmB,KAAnB,IAA4B,MAAM,CAAC,eAJF,EAKjC,KAAK,CAAC,IAAN,CAAW,SALsB,CAAnC;EAOA,OAAO,KAAP;AACD,CAVM","sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { DialogActionsSlots, DialogActionsState } from './DialogActions.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport {\n DIALOG_GAP,\n ACTIONS_END_GRID_AREA,\n ACTIONS_START_GRID_AREA,\n MEDIA_QUERY_BREAKPOINT_SELECTOR,\n} from '../../contexts/constants';\n\nexport const dialogActionsClassNames: SlotClassNames<DialogActionsSlots> = {\n root: 'fui-DialogActions',\n};\n\nconst useStyles = makeStyles({\n root: {\n height: 'fit-content',\n boxSizing: 'border-box',\n display: 'flex',\n ...shorthands.gap(DIALOG_GAP),\n [MEDIA_QUERY_BREAKPOINT_SELECTOR]: {\n flexDirection: 'column',\n justifySelf: 'stretch',\n },\n },\n gridPositionEnd: {\n justifySelf: 'end',\n ...shorthands.gridArea(ACTIONS_END_GRID_AREA),\n },\n gridPositionStart: {\n justifySelf: 'start',\n ...shorthands.gridArea(ACTIONS_START_GRID_AREA),\n },\n});\n\n/**\n * Apply styling to the DialogActions slots based on the state\n */\nexport const useDialogActionsStyles_unstable = (state: DialogActionsState): DialogActionsState => {\n const styles = useStyles();\n state.root.className = mergeClasses(\n dialogActionsClassNames.root,\n styles.root,\n state.position === 'start' && styles.gridPositionStart,\n state.position === 'end' && styles.gridPositionEnd,\n state.root.className,\n );\n return state;\n};\n"],"sourceRoot":"../src/"}
@@ -1,6 +1,5 @@
1
- import { __styles, mergeClasses } from '@griffel/react';
1
+ import { __styles, mergeClasses, shorthands } from '@griffel/react';
2
2
  import { typographyStyles } from '@fluentui/react-theme';
3
- import * as localShorthands from '../../utils/localShorthands';
4
3
  import { BODY_GRID_AREA } from '../../contexts/constants';
5
4
  export const dialogBodyClassNames = {
6
5
  root: 'fui-DialogBody'
@@ -12,12 +11,13 @@ export const dialogBodyClassNames = {
12
11
  const useStyles = /*#__PURE__*/__styles({
13
12
  "root": {
14
13
  "a9b677": "fly5x3f",
15
- "Bqenvij": "f3052tw",
14
+ "Bqenvij": "f1l02sjl",
15
+ "Bmxbyg5": "f5zp4f",
16
16
  "sshi5w": "f1nxs5xn",
17
17
  "B7ck84d": "f1ewtqcl",
18
18
  "Ijaq50": "f6owso0",
19
- "nk6f5a": "foucsne",
20
19
  "Br312pm": "fupswjn",
20
+ "nk6f5a": "foucsne",
21
21
  "Bw0ie65": "f1ka72gx",
22
22
  "Bahqtrf": "fk6fouc",
23
23
  "Be2twd7": "fkhj508",
@@ -25,7 +25,7 @@ const useStyles = /*#__PURE__*/__styles({
25
25
  "Bg96gwp": "f1i3iumi"
26
26
  }
27
27
  }, {
28
- "d": [".fly5x3f{width:100%;}", ".f3052tw{height:-webkit-fit-content;height:-moz-fit-content;height:fit-content;}", ".f1nxs5xn{min-height:32px;}", ".f1ewtqcl{box-sizing:border-box;}", ".f6owso0{grid-row-start:body;}", ".foucsne{grid-row-end:body;}", ".fupswjn{grid-column-start:body;}", ".f1ka72gx{grid-column-end:body;}", ".fk6fouc{font-family:var(--fontFamilyBase);}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".figsok6{font-weight:var(--fontWeightRegular);}", ".f1i3iumi{line-height:var(--lineHeightBase300);}"]
28
+ "d": [".fly5x3f{width:100%;}", ".f1l02sjl{height:100%;}", ".f5zp4f{overflow-y:auto;}", ".f1nxs5xn{min-height:32px;}", ".f1ewtqcl{box-sizing:border-box;}", ".f6owso0{grid-row-start:body;}", ".fupswjn{grid-column-start:body;}", ".foucsne{grid-row-end:body;}", ".f1ka72gx{grid-column-end:body;}", ".fk6fouc{font-family:var(--fontFamilyBase);}", ".fkhj508{font-size:var(--fontSizeBase300);}", ".figsok6{font-weight:var(--fontWeightRegular);}", ".f1i3iumi{line-height:var(--lineHeightBase300);}"]
29
29
  });
30
30
  /**
31
31
  * Apply styling to the DialogBody slots based on the state
@@ -1 +1 @@
1
- {"version":3,"sources":["components/DialogBody/useDialogBodyStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,QAAyC,gBAAzC;AAGA,SAAS,gBAAT,QAAiC,uBAAjC;AACA,OAAO,KAAK,eAAZ,MAAiC,6BAAjC;AACA,SAAS,cAAT,QAA+B,0BAA/B;AAEA,OAAO,MAAM,oBAAoB,GAAoC;EACnE,IAAI,EAAE;AAD6D,CAA9D;AAIP;;AAEG;;AACH,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;AAWA;;AAEG;;;AACH,OAAO,MAAM,4BAA4B,GAAI,KAAD,IAA4C;EACtF,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,oBAAoB,CAAC,IAAtB,EAA4B,MAAM,CAAC,IAAnC,EAAyC,KAAK,CAAC,IAAN,CAAW,SAApD,CAAnC,CAFsF,CAItF;EACA;;EAEA,OAAO,KAAP;AACD,CARM","sourcesContent":["import { makeStyles, mergeClasses } from '@griffel/react';\nimport type { DialogBodySlots, DialogBodyState } from './DialogBody.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport { typographyStyles } from '@fluentui/react-theme';\nimport * as localShorthands from '../../utils/localShorthands';\nimport { BODY_GRID_AREA } from '../../contexts/constants';\n\nexport const dialogBodyClassNames: SlotClassNames<DialogBodySlots> = {\n root: 'fui-DialogBody',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n width: '100%',\n height: 'fit-content',\n minHeight: '32px',\n boxSizing: 'border-box',\n ...localShorthands.gridArea(BODY_GRID_AREA),\n ...typographyStyles.body1,\n },\n});\n\n/**\n * Apply styling to the DialogBody slots based on the state\n */\nexport const useDialogBodyStyles_unstable = (state: DialogBodyState): DialogBodyState => {\n const styles = useStyles();\n state.root.className = mergeClasses(dialogBodyClassNames.root, styles.root, state.root.className);\n\n // TODO Add class names to slots, for example:\n // state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/DialogBody/useDialogBodyStyles.ts"],"names":[],"mappings":"AAAA,mBAAqB,YAArB,EAAmC,UAAnC,QAAqD,gBAArD;AAGA,SAAS,gBAAT,QAAiC,uBAAjC;AACA,SAAS,cAAT,QAA+B,0BAA/B;AAEA,OAAO,MAAM,oBAAoB,GAAoC;EACnE,IAAI,EAAE;AAD6D,CAA9D;AAIP;;AAEG;;AACH,MAAM,SAAS,gBAAG;EAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;IAAA;EAAA;AAAA;EAAA;AAAA,EAAlB;AAYA;;AAEG;;;AACH,OAAO,MAAM,4BAA4B,GAAI,KAAD,IAA4C;EACtF,MAAM,MAAM,GAAG,SAAS,EAAxB;EACA,KAAK,CAAC,IAAN,CAAW,SAAX,GAAuB,YAAY,CAAC,oBAAoB,CAAC,IAAtB,EAA4B,MAAM,CAAC,IAAnC,EAAyC,KAAK,CAAC,IAAN,CAAW,SAApD,CAAnC,CAFsF,CAItF;EACA;;EAEA,OAAO,KAAP;AACD,CARM","sourcesContent":["import { makeStyles, mergeClasses, shorthands } from '@griffel/react';\nimport type { DialogBodySlots, DialogBodyState } from './DialogBody.types';\nimport type { SlotClassNames } from '@fluentui/react-utilities';\nimport { typographyStyles } from '@fluentui/react-theme';\nimport { BODY_GRID_AREA } from '../../contexts/constants';\n\nexport const dialogBodyClassNames: SlotClassNames<DialogBodySlots> = {\n root: 'fui-DialogBody',\n};\n\n/**\n * Styles for the root slot\n */\nconst useStyles = makeStyles({\n root: {\n width: '100%',\n height: '100%',\n overflowY: 'auto',\n minHeight: '32px',\n boxSizing: 'border-box',\n ...shorthands.gridArea(BODY_GRID_AREA),\n ...typographyStyles.body1,\n },\n});\n\n/**\n * Apply styling to the DialogBody slots based on the state\n */\nexport const useDialogBodyStyles_unstable = (state: DialogBodyState): DialogBodyState => {\n const styles = useStyles();\n state.root.className = mergeClasses(dialogBodyClassNames.root, styles.root, state.root.className);\n\n // TODO Add class names to slots, for example:\n // state.mySlot.className = mergeClasses(styles.mySlot, state.mySlot.className);\n\n return state;\n};\n"],"sourceRoot":"../src/"}
@@ -1 +1 @@
1
- {"version":3,"file":"DialogSurface.types.js","sourceRoot":"../src/","sources":["components/DialogSurface/DialogSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { DialogSurfaceContextValue } from '../../contexts';\n\nexport type DialogSurfaceSlots = {\n root: Slot<'div', 'main'>;\n};\n\n/**\n * DialogSurface Props\n */\nexport type DialogSurfaceProps = ComponentProps<DialogSurfaceSlots> & {};\n\nexport type DialogSurfaceContextValues = {\n dialogSurface: DialogSurfaceContextValue;\n};\n\n/**\n * State used in rendering DialogSurface\n */\nexport type DialogSurfaceState = ComponentState<DialogSurfaceSlots>;\n"]}
1
+ {"version":3,"file":"DialogSurface.types.js","sourceRoot":"../src/","sources":["components/DialogSurface/DialogSurface.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ComponentProps, ComponentState, Slot } from '@fluentui/react-utilities';\nimport { DialogSurfaceContextValue } from '../../contexts';\n\nexport type DialogSurfaceSlots = {\n /**\n * Dimmed background of dialog.\n * The default backdrop is rendered as a `<div>` with styling.\n * This slot expects a `<div>` element which will replace the default backdrop.\n * The backdrop should have `aria-hidden=\"true\"`.\n *\n * By default if `DialogSurface` is `<dialog>` element the backdrop is ignored,\n * since native `<dialog>` element supports [::backdrop](https://developer.mozilla.org/en-US/docs/Web/CSS/::backdrop)\n */\n backdrop?: Slot<'div'>;\n root: NonNullable<Slot<'dialog', 'div'>>;\n};\n\n/** @internal */\nexport type DialogSurfaceElement = HTMLDialogElement | HTMLDivElement;\n\n/** @internal */\nexport type DialogSurfaceElementIntersection = HTMLDialogElement & HTMLDivElement;\n\n/**\n * DialogSurface Props\n *\n * Omits basic types from native `dialog` (`open`, `onCancel` and `onClose`)\n * to ensure `onOpenChange`, `open` and `defaultOpen` from `Dialog` is used instead\n */\nexport type DialogSurfaceProps = Omit<ComponentProps<DialogSurfaceSlots>, 'open' | 'onCancel' | 'onClose'>;\n\nexport type DialogSurfaceContextValues = {\n dialogSurface: DialogSurfaceContextValue;\n};\n\n/**\n * State used in rendering DialogSurface\n */\nexport type DialogSurfaceState = ComponentState<DialogSurfaceSlots>;\n"]}
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { getSlots } from '@fluentui/react-utilities';
3
3
  import { DialogSurfaceProvider } from '../../contexts';
4
+ import { Portal } from '@fluentui/react-portal';
4
5
  /**
5
6
  * Render the final JSX of DialogSurface
6
7
  */
@@ -10,9 +11,10 @@ export const renderDialogSurface_unstable = (state, contextValues) => {
10
11
  slots,
11
12
  slotProps
12
13
  } = getSlots(state);
13
- return /*#__PURE__*/React.createElement(DialogSurfaceProvider, {
14
+ return /*#__PURE__*/React.createElement(Portal, null, slots.backdrop && /*#__PURE__*/React.createElement(slots.backdrop, { ...slotProps.backdrop
15
+ }), /*#__PURE__*/React.createElement(DialogSurfaceProvider, {
14
16
  value: contextValues.dialogSurface
15
17
  }, /*#__PURE__*/React.createElement(slots.root, { ...slotProps.root
16
- }));
18
+ })));
17
19
  };
18
20
  //# sourceMappingURL=renderDialogSurface.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["components/DialogSurface/renderDialogSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAEA,SAAS,qBAAT,QAAsC,gBAAtC;AAEA;;AAEG;;AACH,OAAO,MAAM,4BAA4B,GAAG,CAAC,KAAD,EAA4B,aAA5B,KAAyE;EACnH,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAqB,KAArB,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CADF,CADF;AAKD,CARM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { DialogSurfaceState, DialogSurfaceSlots, DialogSurfaceContextValues } from './DialogSurface.types';\nimport { DialogSurfaceProvider } from '../../contexts';\n\n/**\n * Render the final JSX of DialogSurface\n */\nexport const renderDialogSurface_unstable = (state: DialogSurfaceState, contextValues: DialogSurfaceContextValues) => {\n const { slots, slotProps } = getSlots<DialogSurfaceSlots>(state);\n\n return (\n <DialogSurfaceProvider value={contextValues.dialogSurface}>\n <slots.root {...slotProps.root} />\n </DialogSurfaceProvider>\n );\n};\n"],"sourceRoot":"../src/"}
1
+ {"version":3,"sources":["components/DialogSurface/renderDialogSurface.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,QAAT,QAAyB,2BAAzB;AAEA,SAAS,qBAAT,QAAsC,gBAAtC;AACA,SAAS,MAAT,QAAuB,wBAAvB;AAEA;;AAEG;;AACH,OAAO,MAAM,4BAA4B,GAAG,CAAC,KAAD,EAA4B,aAA5B,KAAyE;EACnH,MAAM;IAAE,KAAF;IAAS;EAAT,IAAuB,QAAQ,CAAqB,KAArB,CAArC;EAEA,oBACE,KAAA,CAAA,aAAA,CAAC,MAAD,EAAO,IAAP,EACG,KAAK,CAAC,QAAN,iBAAkB,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,QAAP,EAAe,EAAA,GAAK,SAAS,CAAC;EAAf,CAAf,CADrB,eAEE,KAAA,CAAA,aAAA,CAAC,qBAAD,EAAsB;IAAC,KAAK,EAAE,aAAa,CAAC;EAAtB,CAAtB,eACE,KAAA,CAAA,aAAA,CAAC,KAAK,CAAC,IAAP,EAAW,EAAA,GAAK,SAAS,CAAC;EAAf,CAAX,CADF,CAFF,CADF;AAQD,CAXM","sourcesContent":["import * as React from 'react';\nimport { getSlots } from '@fluentui/react-utilities';\nimport type { DialogSurfaceState, DialogSurfaceSlots, DialogSurfaceContextValues } from './DialogSurface.types';\nimport { DialogSurfaceProvider } from '../../contexts';\nimport { Portal } from '@fluentui/react-portal';\n\n/**\n * Render the final JSX of DialogSurface\n */\nexport const renderDialogSurface_unstable = (state: DialogSurfaceState, contextValues: DialogSurfaceContextValues) => {\n const { slots, slotProps } = getSlots<DialogSurfaceSlots>(state);\n\n return (\n <Portal>\n {slots.backdrop && <slots.backdrop {...slotProps.backdrop} />}\n <DialogSurfaceProvider value={contextValues.dialogSurface}>\n <slots.root {...slotProps.root} />\n </DialogSurfaceProvider>\n </Portal>\n );\n};\n"],"sourceRoot":"../src/"}
@@ -1,7 +1,7 @@
1
- import { getNativeElementProps, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';
2
- import { useModalAttributes } from '@fluentui/react-tabster';
1
+ import { getNativeElementProps, resolveShorthand, useEventCallback, useMergedRefs, isResolvedShorthand } from '@fluentui/react-utilities';
3
2
  import { useDialogContext_unstable } from '../../contexts';
4
3
  import { isEscapeKeyDismiss } from '../../utils';
4
+ import { useModalAttributes } from '@fluentui/react-tabster';
5
5
  /**
6
6
  * Create the state required to render DialogSurface.
7
7
  *
@@ -13,20 +13,98 @@ import { isEscapeKeyDismiss } from '../../utils';
13
13
  */
14
14
 
15
15
  export const useDialogSurface_unstable = (props, ref) => {
16
- const modalType = useDialogContext_unstable(ctx => ctx.modalType);
17
16
  const {
18
- as = 'div'
17
+ backdrop,
18
+ as
19
19
  } = props;
20
- const contentRef = useDialogContext_unstable(ctx => ctx.contentRef);
20
+ const isNativeDialog = as === 'dialog' || as === undefined;
21
+ const modalType = useDialogContext_unstable(ctx => ctx.modalType);
22
+ const dialogRef = useDialogContext_unstable(ctx => ctx.dialogRef);
23
+ const open = useDialogContext_unstable(ctx => ctx.open);
24
+ const requestOpenChange = useDialogContext_unstable(ctx => ctx.requestOpenChange);
21
25
  const dialogTitleID = useDialogContext_unstable(ctx => ctx.dialogTitleID);
22
26
  const dialogBodyID = useDialogContext_unstable(ctx => ctx.dialogBodyID);
23
- const requestOpenChange = useDialogContext_unstable(ctx => ctx.requestOpenChange);
24
- const {
25
- modalAttributes
26
- } = useModalAttributes({
27
- trapFocus: modalType !== 'non-modal'
27
+ const handleNativeClick = useEventCallback(event => {
28
+ var _a;
29
+
30
+ (_a = props.onClick) === null || _a === void 0 ? void 0 : _a.call(props, event);
31
+
32
+ if (modalType === 'alert' || event.target !== event.currentTarget) {
33
+ return;
34
+ }
35
+
36
+ const {
37
+ clientX,
38
+ clientY
39
+ } = event;
40
+ const {
41
+ top,
42
+ left,
43
+ width,
44
+ height
45
+ } = event.currentTarget.getBoundingClientRect();
46
+ const isBackdropClick = top > clientY || clientY > top + height || left > clientX || clientX > left + width;
47
+
48
+ if (isBackdropClick) {
49
+ requestOpenChange({
50
+ event,
51
+ open: false,
52
+ type: 'backdropClick'
53
+ });
54
+ }
55
+ });
56
+ const handleNativeCancel = useEventCallback(event => {
57
+ var _a, _b;
58
+
59
+ (_b = (_a = props).onCancel) === null || _b === void 0 ? void 0 : _b.call(_a, event);
60
+
61
+ if (event.currentTarget !== event.target) {
62
+ return;
63
+ }
64
+
65
+ if (modalType !== 'alert') {
66
+ requestOpenChange({
67
+ event,
68
+ open: false,
69
+ type: 'dialogCancel'
70
+ });
71
+ }
72
+
73
+ event.preventDefault();
74
+ });
75
+ const handleNativeClose = useEventCallback(event => {
76
+ var _a, _b;
77
+
78
+ (_b = (_a = props).onClose) === null || _b === void 0 ? void 0 : _b.call(_a, event); // Ensure dialog remains open if force closed by close event
79
+
80
+ if (event.currentTarget.open !== open) {
81
+ if (open) {
82
+ if (modalType === 'non-modal') {
83
+ event.currentTarget.show();
84
+ } else {
85
+ event.currentTarget.showModal();
86
+ }
87
+ } else {
88
+ event.currentTarget.close();
89
+ }
90
+ }
91
+ });
92
+ const handledBackdropClick = useEventCallback(event => {
93
+ var _a, _b;
94
+
95
+ if (isResolvedShorthand(props.backdrop)) {
96
+ (_b = (_a = props.backdrop).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
97
+ }
98
+
99
+ if (modalType === 'modal' && !event.isDefaultPrevented()) {
100
+ requestOpenChange({
101
+ event,
102
+ open: false,
103
+ type: 'backdropClick'
104
+ });
105
+ }
28
106
  });
29
- const handleRootKeyDown = useEventCallback(event => {
107
+ const handleKeyDown = useEventCallback(event => {
30
108
  var _a;
31
109
 
32
110
  (_a = props.onKeyDown) === null || _a === void 0 ? void 0 : _a.call(props, event);
@@ -36,23 +114,44 @@ export const useDialogSurface_unstable = (props, ref) => {
36
114
  event,
37
115
  open: false,
38
116
  type: 'escapeKeyDown'
39
- });
40
- event.preventDefault();
117
+ }); // stop propagation to avoid conflicting with other elements that listen for `Escape`
118
+ // e,g: nested Dialog, Popover, Menu and Tooltip
119
+
120
+ event.stopPropagation();
41
121
  }
42
122
  });
123
+ const {
124
+ modalAttributes
125
+ } = useModalAttributes({
126
+ trapFocus: modalType !== 'non-modal'
127
+ });
43
128
  return {
44
129
  components: {
45
- root: 'div'
130
+ backdrop: 'div',
131
+ root: 'dialog'
46
132
  },
47
- root: getNativeElementProps(as, {
48
- ref: useMergedRefs(ref, contentRef),
49
- 'aria-modal': modalType !== 'non-modal',
50
- 'aria-describedby': dialogBodyID,
51
- 'aria-labelledby': props['aria-label'] ? undefined : dialogTitleID,
52
- role: modalType === 'alert' ? 'alertdialog' : 'dialog',
133
+ backdrop: resolveShorthand(backdrop, {
134
+ required: !isNativeDialog && open && modalType !== 'non-modal',
135
+ defaultProps: {
136
+ 'aria-hidden': 'true',
137
+ onClick: handledBackdropClick
138
+ }
139
+ }),
140
+ root: getNativeElementProps(as !== null && as !== void 0 ? as : 'dialog', { ...(isNativeDialog ? {
141
+ role: modalType === 'alert' ? 'alertdialog' : undefined,
142
+ onClose: handleNativeClose,
143
+ onClick: handleNativeClick,
144
+ onCancel: handleNativeCancel
145
+ } : {
146
+ 'aria-modal': modalType !== 'non-modal',
147
+ role: modalType === 'alert' ? 'alertdialog' : 'dialog'
148
+ }),
53
149
  ...props,
54
150
  ...modalAttributes,
55
- onKeyDown: handleRootKeyDown
151
+ onKeyDown: handleKeyDown,
152
+ 'aria-describedby': dialogBodyID,
153
+ 'aria-labelledby': props['aria-label'] ? undefined : dialogTitleID,
154
+ ref: useMergedRefs(ref, dialogRef)
56
155
  })
57
156
  };
58
157
  };