@react-aria/dialog 3.0.0-alpha.2 → 3.0.0-nightly-641446f65-240905

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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
1
  # @react-aria/dialog
2
2
 
3
- This package is part of [react-spectrum](https://github.com/adobe-private/react-spectrum-v3). See the repo for more details.
3
+ This package is part of [react-spectrum](https://github.com/adobe/react-spectrum). See the repo for more details.
@@ -0,0 +1,17 @@
1
+ import {useDialog as $40df3f8667284809$export$d55e7ee900f34e93} from "./useDialog.mjs";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$40df3f8667284809$export$d55e7ee900f34e93 as useDialog};
17
+ //# sourceMappingURL=module.js.map
package/dist/main.js CHANGED
@@ -1,122 +1,22 @@
1
- var _react2 = require("react");
1
+ var $e7b76b4fae4e4c55$exports = require("./useDialog.main.js");
2
2
 
3
- var _react = $parcel$interopDefault(_react2);
4
3
 
5
- var useEffect = _react2.useEffect;
6
- var useContext = _react2.useContext;
7
- var useState = _react2.useState;
8
-
9
- var _babelRuntimeHelpersEsmSlicedToArray = $parcel$interopDefault(require("@babel/runtime/helpers/esm/slicedToArray"));
10
-
11
- function $parcel$interopDefault(a) {
12
- return a && a.__esModule ? a.default : a;
13
- }
14
-
15
- function useDialog(props) {
16
- var ref = props.ref,
17
- _props$role = props.role,
18
- role = _props$role === void 0 ? 'dialog' : _props$role; // Focus the dialog itself on mount, unless a child element is already focused.
19
-
20
- useEffect(function () {
21
- if (ref.current && !ref.current.contains(document.activeElement)) {
22
- ref.current.focus();
23
- }
24
- }, [ref]);
25
- return {
26
- dialogProps: {
27
- role: role,
28
- tabIndex: -1
29
- }
30
- };
31
- }
32
-
33
- exports.useDialog = useDialog;
34
-
35
- var $a1ecb7059a03661ca04dde7373d441$var$Context = _react.createContext(null); // Each ModalProvider tracks how many modals are open in its subtree. On mount, the modals
36
- // trigger `addModal` to increment the count, and trigger `removeModal` on unmount to decrement it.
37
- // This is done recursively so that all parent providers are incremented and decremented.
38
- // If the modal count is greater than zero, we add `aria-hidden` to this provider to hide its
39
- // subtree from screen readers. This is done using React context in order to account for things
40
- // like portals, which can cause the React tree and the DOM tree to differ significantly in structure.
41
- // TODO: maybe move this?
42
-
43
-
44
- function ModalProvider(props) {
45
- var children = props.children;
46
- var parent = useContext($a1ecb7059a03661ca04dde7373d441$var$Context);
47
-
48
- var _useState = useState(parent ? parent.modalCount : 0),
49
- _useState2 = _babelRuntimeHelpersEsmSlicedToArray(_useState, 2),
50
- modalCount = _useState2[0],
51
- setModalCount = _useState2[1];
52
-
53
- var context = {
54
- parent: parent,
55
- modalCount: modalCount,
56
- addModal: function addModal() {
57
- setModalCount(function (count) {
58
- return count + 1;
59
- });
60
-
61
- if (parent) {
62
- parent.addModal();
63
- }
64
- },
65
- removeModal: function removeModal() {
66
- setModalCount(function (count) {
67
- return count - 1;
68
- });
69
-
70
- if (parent) {
71
- parent.removeModal();
72
- }
73
- }
74
- };
75
- return _react.createElement($a1ecb7059a03661ca04dde7373d441$var$Context.Provider, {
76
- value: context
77
- }, children);
78
- }
79
-
80
- exports.ModalProvider = ModalProvider;
81
-
82
- function useModalProvider() {
83
- var context = useContext($a1ecb7059a03661ca04dde7373d441$var$Context);
84
- return {
85
- modalProviderProps: {
86
- 'aria-hidden': context && context.modalCount > 0 ? true : null
87
- }
88
- };
89
- }
90
-
91
- exports.useModalProvider = useModalProvider;
92
-
93
- function useModalDialog() {
94
- // Add aria-hidden to all parent providers on mount, and restore on unmount.
95
- var context = useContext($a1ecb7059a03661ca04dde7373d441$var$Context);
96
-
97
- if (!context) {
98
- throw new Error('Modal is not contained within a provider');
99
- }
100
-
101
- useEffect(function () {
102
- if (!context || !context.parent) {
103
- return;
104
- } // The immediate context is from the provider containing this modal, so we only
105
- // want to trigger aria-hidden on its parents not on the modal provider itself.
106
-
107
-
108
- context.parent.addModal();
109
- return function () {
110
- if (context && context.parent) {
111
- context.parent.removeModal();
112
- }
113
- };
114
- }, [context, context.parent]);
115
- return {
116
- modalProps: {
117
- 'aria-modal': true
118
- }
119
- };
4
+ function $parcel$export(e, n, v, s) {
5
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
120
6
  }
121
7
 
122
- exports.useModalDialog = useModalDialog;
8
+ $parcel$export(module.exports, "useDialog", () => $e7b76b4fae4e4c55$exports.useDialog);
9
+ /*
10
+ * Copyright 2020 Adobe. All rights reserved.
11
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
12
+ * you may not use this file except in compliance with the License. You may obtain a copy
13
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software distributed under
16
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
17
+ * OF ANY KIND, either express or implied. See the License for the specific language
18
+ * governing permissions and limitations under the License.
19
+ */
20
+
21
+
22
+ //# sourceMappingURL=main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/dialog/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDialog} from './useDialog';\nexport type {AriaDialogProps} from '@react-types/dialog';\nexport type {DialogAria} from './useDialog';\n"],"names":[],"version":3,"file":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,96 +1,17 @@
1
- import _react, { useEffect, useContext, useState } from "react";
2
- export function useDialog(props) {
3
- let {
4
- ref,
5
- role = 'dialog'
6
- } = props; // Focus the dialog itself on mount, unless a child element is already focused.
7
-
8
- useEffect(() => {
9
- if (ref.current && !ref.current.contains(document.activeElement)) {
10
- ref.current.focus();
11
- }
12
- }, [ref]);
13
- return {
14
- dialogProps: {
15
- role,
16
- tabIndex: -1
17
- }
18
- };
19
- }
20
-
21
- const $b94bc035783bed22c331cbc48a6429$var$Context = _react.createContext(null); // Each ModalProvider tracks how many modals are open in its subtree. On mount, the modals
22
- // trigger `addModal` to increment the count, and trigger `removeModal` on unmount to decrement it.
23
- // This is done recursively so that all parent providers are incremented and decremented.
24
- // If the modal count is greater than zero, we add `aria-hidden` to this provider to hide its
25
- // subtree from screen readers. This is done using React context in order to account for things
26
- // like portals, which can cause the React tree and the DOM tree to differ significantly in structure.
27
- // TODO: maybe move this?
28
-
29
-
30
- export function ModalProvider(props) {
31
- let {
32
- children
33
- } = props;
34
- let parent = useContext($b94bc035783bed22c331cbc48a6429$var$Context);
35
- let [modalCount, setModalCount] = useState(parent ? parent.modalCount : 0);
36
- let context = {
37
- parent,
38
- modalCount,
39
-
40
- addModal() {
41
- setModalCount(count => count + 1);
42
-
43
- if (parent) {
44
- parent.addModal();
45
- }
46
- },
47
-
48
- removeModal() {
49
- setModalCount(count => count - 1);
50
-
51
- if (parent) {
52
- parent.removeModal();
53
- }
54
- }
55
-
56
- };
57
- return _react.createElement($b94bc035783bed22c331cbc48a6429$var$Context.Provider, {
58
- value: context
59
- }, children);
60
- }
61
- export function useModalProvider() {
62
- let context = useContext($b94bc035783bed22c331cbc48a6429$var$Context);
63
- return {
64
- modalProviderProps: {
65
- 'aria-hidden': context && context.modalCount > 0 ? true : null
66
- }
67
- };
68
- }
69
- export function useModalDialog() {
70
- // Add aria-hidden to all parent providers on mount, and restore on unmount.
71
- let context = useContext($b94bc035783bed22c331cbc48a6429$var$Context);
72
-
73
- if (!context) {
74
- throw new Error('Modal is not contained within a provider');
75
- }
76
-
77
- useEffect(() => {
78
- if (!context || !context.parent) {
79
- return;
80
- } // The immediate context is from the provider containing this modal, so we only
81
- // want to trigger aria-hidden on its parents not on the modal provider itself.
82
-
83
-
84
- context.parent.addModal();
85
- return () => {
86
- if (context && context.parent) {
87
- context.parent.removeModal();
88
- }
89
- };
90
- }, [context, context.parent]);
91
- return {
92
- modalProps: {
93
- 'aria-modal': true
94
- }
95
- };
96
- }
1
+ import {useDialog as $40df3f8667284809$export$d55e7ee900f34e93} from "./useDialog.module.js";
2
+
3
+ /*
4
+ * Copyright 2020 Adobe. All rights reserved.
5
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License. You may obtain a copy
7
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
8
+ *
9
+ * Unless required by applicable law or agreed to in writing, software distributed under
10
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
11
+ * OF ANY KIND, either express or implied. See the License for the specific language
12
+ * governing permissions and limitations under the License.
13
+ */
14
+
15
+
16
+ export {$40df3f8667284809$export$d55e7ee900f34e93 as useDialog};
17
+ //# sourceMappingURL=module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;AAAA;;;;;;;;;;CAUC","sources":["packages/@react-aria/dialog/src/index.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDialog} from './useDialog';\nexport type {AriaDialogProps} from '@react-types/dialog';\nexport type {DialogAria} from './useDialog';\n"],"names":[],"version":3,"file":"module.js.map"}
package/dist/types.d.ts CHANGED
@@ -1,23 +1,16 @@
1
- import { AllHTMLAttributes, RefObject, AriaAttributes, ReactNode } from "react";
2
- interface DialogProps {
3
- ref: RefObject<HTMLElement | null>;
4
- role?: 'dialog' | 'alertdialog';
1
+ import { AriaDialogProps } from "@react-types/dialog";
2
+ import { DOMAttributes, FocusableElement, RefObject } from "@react-types/shared";
3
+ export interface DialogAria {
4
+ /** Props for the dialog container element. */
5
+ dialogProps: DOMAttributes;
6
+ /** Props for the dialog title element. */
7
+ titleProps: DOMAttributes;
5
8
  }
6
- interface DialogAria {
7
- dialogProps: AllHTMLAttributes<HTMLElement>;
8
- }
9
- export function useDialog(props: DialogProps): DialogAria;
10
- interface ModalProviderProps {
11
- children: ReactNode;
12
- }
13
- export function ModalProvider(props: ModalProviderProps): JSX.Element;
14
- interface ModalProviderAria {
15
- modalProviderProps: AriaAttributes;
16
- }
17
- export function useModalProvider(): ModalProviderAria;
18
- interface ModalDialogAria {
19
- modalProps: AriaAttributes;
20
- }
21
- export function useModalDialog(): ModalDialogAria;
9
+ /**
10
+ * Provides the behavior and accessibility implementation for a dialog component.
11
+ * A dialog is an overlay shown above other content in an application.
12
+ */
13
+ export function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElement | null>): DialogAria;
14
+ export type { AriaDialogProps } from '@react-types/dialog';
22
15
 
23
16
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/Users/govett/dev/react-spectrum/packages/@react-aria/dialog/src/packages/@react-aria/dialog/src/useDialog.ts","/Users/govett/dev/react-spectrum/packages/@react-aria/dialog/src/packages/@react-aria/dialog/src/useModalDialog.tsx"],"names":[],"mappings":";AAEA;IACE,GAAG,EAAE,UAAU,WAAW,GAAG,IAAI,CAAC,CAAC;IACnC,IAAI,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAA;CAChC;AAED;IACE,WAAW,EAAE,kBAAkB,WAAW,CAAC,CAAA;CAC5C;AAED,0BAA0B,KAAK,EAAE,WAAW,GAAG,UAAU,CAgBxD;ACzBD;IACE,QAAQ,EAAE,SAAS,CAAA;CACpB;AAkBD,8BAA8B,KAAK,EAAE,kBAAkB,eA0BtD;AAED;IACE,kBAAkB,EAAE,cAAc,CAAA;CACnC;AAED,oCAAoC,iBAAiB,CAOpD;AAED;IACE,UAAU,EAAE,cAAc,CAAA;CAC3B;AAED,kCAAkC,eAAe,CA2BhD","file":"types.d.ts.map"}
1
+ {"mappings":";;AAmBA;IACE,8CAA8C;IAC9C,WAAW,EAAE,aAAa,CAAC;IAE3B,0CAA0C;IAC1C,UAAU,EAAE,aAAa,CAAA;CAC1B;AAED;;;GAGG;AACH,0BAA0B,KAAK,EAAE,eAAe,EAAE,GAAG,EAAE,UAAU,gBAAgB,GAAG,IAAI,CAAC,GAAG,UAAU,CA0DrG;AC7ED,YAAY,EAAC,eAAe,EAAC,MAAM,qBAAqB,CAAC","sources":["packages/@react-aria/dialog/src/packages/@react-aria/dialog/src/useDialog.ts","packages/@react-aria/dialog/src/packages/@react-aria/dialog/src/index.ts","packages/@react-aria/dialog/src/index.ts"],"sourcesContent":[null,null,"/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\nexport {useDialog} from './useDialog';\nexport type {AriaDialogProps} from '@react-types/dialog';\nexport type {DialogAria} from './useDialog';\n"],"names":[],"version":3,"file":"types.d.ts.map"}
@@ -0,0 +1,83 @@
1
+ var $HoXek$reactariautils = require("@react-aria/utils");
2
+ var $HoXek$reactariafocus = require("@react-aria/focus");
3
+ var $HoXek$react = require("react");
4
+ var $HoXek$reactariaoverlays = require("@react-aria/overlays");
5
+
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
9
+ }
10
+
11
+ $parcel$export(module.exports, "useDialog", () => $e7b76b4fae4e4c55$export$d55e7ee900f34e93);
12
+ /*
13
+ * Copyright 2020 Adobe. All rights reserved.
14
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License. You may obtain a copy
16
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software distributed under
19
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
20
+ * OF ANY KIND, either express or implied. See the License for the specific language
21
+ * governing permissions and limitations under the License.
22
+ */
23
+
24
+
25
+
26
+ function $e7b76b4fae4e4c55$export$d55e7ee900f34e93(props, ref) {
27
+ let { role: role = 'dialog' } = props;
28
+ let titleId = (0, $HoXek$reactariautils.useSlotId)();
29
+ titleId = props['aria-label'] ? undefined : titleId;
30
+ let isRefocusing = (0, $HoXek$react.useRef)(false);
31
+ // Focus the dialog itself on mount, unless a child element is already focused.
32
+ (0, $HoXek$react.useEffect)(()=>{
33
+ if (ref.current && !ref.current.contains(document.activeElement)) {
34
+ (0, $HoXek$reactariafocus.focusSafely)(ref.current);
35
+ // Safari on iOS does not move the VoiceOver cursor to the dialog
36
+ // or announce that it has opened until it has rendered. A workaround
37
+ // is to wait for half a second, then blur and re-focus the dialog.
38
+ let timeout = setTimeout(()=>{
39
+ if (document.activeElement === ref.current) {
40
+ isRefocusing.current = true;
41
+ if (ref.current) {
42
+ ref.current.blur();
43
+ (0, $HoXek$reactariafocus.focusSafely)(ref.current);
44
+ }
45
+ isRefocusing.current = false;
46
+ }
47
+ }, 500);
48
+ return ()=>{
49
+ clearTimeout(timeout);
50
+ };
51
+ }
52
+ }, [
53
+ ref
54
+ ]);
55
+ (0, $HoXek$reactariaoverlays.useOverlayFocusContain)();
56
+ // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused
57
+ // on mount when inside an iframe, no matter which element we programmatically focus.
58
+ // See https://bugs.webkit.org/show_bug.cgi?id=211934.
59
+ // useModal sets aria-hidden on all elements outside the dialog, so the dialog will behave as a modal
60
+ // even without aria-modal on the dialog itself.
61
+ return {
62
+ dialogProps: {
63
+ ...(0, $HoXek$reactariautils.filterDOMProps)(props, {
64
+ labelable: true
65
+ }),
66
+ role: role,
67
+ tabIndex: -1,
68
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
69
+ // Prevent blur events from reaching useOverlay, which may cause
70
+ // popovers to close. Since focus is contained within the dialog,
71
+ // we don't want this to occur due to the above useEffect.
72
+ onBlur: (e)=>{
73
+ if (isRefocusing.current) e.stopPropagation();
74
+ }
75
+ },
76
+ titleProps: {
77
+ id: titleId
78
+ }
79
+ };
80
+ }
81
+
82
+
83
+ //# sourceMappingURL=useDialog.main.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAqBM,SAAS,0CAAU,KAAsB,EAAE,GAAuC;IACvF,IAAI,QAAC,OAAO,UAAS,GAAG;IACxB,IAAI,UAA8B,CAAA,GAAA,+BAAQ;IAC1C,UAAU,KAAK,CAAC,aAAa,GAAG,YAAY;IAE5C,IAAI,eAAe,CAAA,GAAA,mBAAK,EAAE;IAE1B,+EAA+E;IAC/E,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,aAAa,GAAG;YAChE,CAAA,GAAA,iCAAU,EAAE,IAAI,OAAO;YAEvB,iEAAiE;YACjE,qEAAqE;YACrE,mEAAmE;YACnE,IAAI,UAAU,WAAW;gBACvB,IAAI,SAAS,aAAa,KAAK,IAAI,OAAO,EAAE;oBAC1C,aAAa,OAAO,GAAG;oBACvB,IAAI,IAAI,OAAO,EAAE;wBACf,IAAI,OAAO,CAAC,IAAI;wBAChB,CAAA,GAAA,iCAAU,EAAE,IAAI,OAAO;oBACzB;oBACA,aAAa,OAAO,GAAG;gBACzB;YACF,GAAG;YAEH,OAAO;gBACL,aAAa;YACf;QACF;IACF,GAAG;QAAC;KAAI;IAER,CAAA,GAAA,+CAAqB;IAErB,sGAAsG;IACtG,qFAAqF;IACrF,sDAAsD;IACtD,qGAAqG;IACrG,gDAAgD;IAChD,OAAO;QACL,aAAa;YACX,GAAG,CAAA,GAAA,oCAAa,EAAE,OAAO;gBAAC,WAAW;YAAI,EAAE;kBAC3C;YACA,UAAU;YACV,mBAAmB,KAAK,CAAC,kBAAkB,IAAI;YAC/C,gEAAgE;YAChE,iEAAiE;YACjE,0DAA0D;YAC1D,QAAQ,CAAA;gBACN,IAAI,aAAa,OAAO,EACtB,EAAE,eAAe;YAErB;QACF;QACA,YAAY;YACV,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/dialog/src/useDialog.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaDialogProps} from '@react-types/dialog';\nimport {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {filterDOMProps, useSlotId} from '@react-aria/utils';\nimport {focusSafely} from '@react-aria/focus';\nimport {useEffect, useRef} from 'react';\nimport {useOverlayFocusContain} from '@react-aria/overlays';\n\nexport interface DialogAria {\n /** Props for the dialog container element. */\n dialogProps: DOMAttributes,\n\n /** Props for the dialog title element. */\n titleProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a dialog component.\n * A dialog is an overlay shown above other content in an application.\n */\nexport function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElement | null>): DialogAria {\n let {role = 'dialog'} = props;\n let titleId: string | undefined = useSlotId();\n titleId = props['aria-label'] ? undefined : titleId;\n\n let isRefocusing = useRef(false);\n\n // Focus the dialog itself on mount, unless a child element is already focused.\n useEffect(() => {\n if (ref.current && !ref.current.contains(document.activeElement)) {\n focusSafely(ref.current);\n\n // Safari on iOS does not move the VoiceOver cursor to the dialog\n // or announce that it has opened until it has rendered. A workaround\n // is to wait for half a second, then blur and re-focus the dialog.\n let timeout = setTimeout(() => {\n if (document.activeElement === ref.current) {\n isRefocusing.current = true;\n if (ref.current) {\n ref.current.blur();\n focusSafely(ref.current);\n }\n isRefocusing.current = false;\n }\n }, 500);\n\n return () => {\n clearTimeout(timeout);\n };\n }\n }, [ref]);\n\n useOverlayFocusContain();\n\n // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused\n // on mount when inside an iframe, no matter which element we programmatically focus.\n // See https://bugs.webkit.org/show_bug.cgi?id=211934.\n // useModal sets aria-hidden on all elements outside the dialog, so the dialog will behave as a modal\n // even without aria-modal on the dialog itself.\n return {\n dialogProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n tabIndex: -1,\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n // Prevent blur events from reaching useOverlay, which may cause\n // popovers to close. Since focus is contained within the dialog,\n // we don't want this to occur due to the above useEffect.\n onBlur: e => {\n if (isRefocusing.current) {\n e.stopPropagation();\n }\n }\n },\n titleProps: {\n id: titleId\n }\n };\n}\n"],"names":[],"version":3,"file":"useDialog.main.js.map"}
@@ -0,0 +1,78 @@
1
+ import {useSlotId as $i6df2$useSlotId, filterDOMProps as $i6df2$filterDOMProps} from "@react-aria/utils";
2
+ import {focusSafely as $i6df2$focusSafely} from "@react-aria/focus";
3
+ import {useRef as $i6df2$useRef, useEffect as $i6df2$useEffect} from "react";
4
+ import {useOverlayFocusContain as $i6df2$useOverlayFocusContain} from "@react-aria/overlays";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $40df3f8667284809$export$d55e7ee900f34e93(props, ref) {
21
+ let { role: role = 'dialog' } = props;
22
+ let titleId = (0, $i6df2$useSlotId)();
23
+ titleId = props['aria-label'] ? undefined : titleId;
24
+ let isRefocusing = (0, $i6df2$useRef)(false);
25
+ // Focus the dialog itself on mount, unless a child element is already focused.
26
+ (0, $i6df2$useEffect)(()=>{
27
+ if (ref.current && !ref.current.contains(document.activeElement)) {
28
+ (0, $i6df2$focusSafely)(ref.current);
29
+ // Safari on iOS does not move the VoiceOver cursor to the dialog
30
+ // or announce that it has opened until it has rendered. A workaround
31
+ // is to wait for half a second, then blur and re-focus the dialog.
32
+ let timeout = setTimeout(()=>{
33
+ if (document.activeElement === ref.current) {
34
+ isRefocusing.current = true;
35
+ if (ref.current) {
36
+ ref.current.blur();
37
+ (0, $i6df2$focusSafely)(ref.current);
38
+ }
39
+ isRefocusing.current = false;
40
+ }
41
+ }, 500);
42
+ return ()=>{
43
+ clearTimeout(timeout);
44
+ };
45
+ }
46
+ }, [
47
+ ref
48
+ ]);
49
+ (0, $i6df2$useOverlayFocusContain)();
50
+ // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused
51
+ // on mount when inside an iframe, no matter which element we programmatically focus.
52
+ // See https://bugs.webkit.org/show_bug.cgi?id=211934.
53
+ // useModal sets aria-hidden on all elements outside the dialog, so the dialog will behave as a modal
54
+ // even without aria-modal on the dialog itself.
55
+ return {
56
+ dialogProps: {
57
+ ...(0, $i6df2$filterDOMProps)(props, {
58
+ labelable: true
59
+ }),
60
+ role: role,
61
+ tabIndex: -1,
62
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
63
+ // Prevent blur events from reaching useOverlay, which may cause
64
+ // popovers to close. Since focus is contained within the dialog,
65
+ // we don't want this to occur due to the above useEffect.
66
+ onBlur: (e)=>{
67
+ if (isRefocusing.current) e.stopPropagation();
68
+ }
69
+ },
70
+ titleProps: {
71
+ id: titleId
72
+ }
73
+ };
74
+ }
75
+
76
+
77
+ export {$40df3f8667284809$export$d55e7ee900f34e93 as useDialog};
78
+ //# sourceMappingURL=useDialog.module.js.map
@@ -0,0 +1,78 @@
1
+ import {useSlotId as $i6df2$useSlotId, filterDOMProps as $i6df2$filterDOMProps} from "@react-aria/utils";
2
+ import {focusSafely as $i6df2$focusSafely} from "@react-aria/focus";
3
+ import {useRef as $i6df2$useRef, useEffect as $i6df2$useEffect} from "react";
4
+ import {useOverlayFocusContain as $i6df2$useOverlayFocusContain} from "@react-aria/overlays";
5
+
6
+ /*
7
+ * Copyright 2020 Adobe. All rights reserved.
8
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License. You may obtain a copy
10
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
11
+ *
12
+ * Unless required by applicable law or agreed to in writing, software distributed under
13
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
14
+ * OF ANY KIND, either express or implied. See the License for the specific language
15
+ * governing permissions and limitations under the License.
16
+ */
17
+
18
+
19
+
20
+ function $40df3f8667284809$export$d55e7ee900f34e93(props, ref) {
21
+ let { role: role = 'dialog' } = props;
22
+ let titleId = (0, $i6df2$useSlotId)();
23
+ titleId = props['aria-label'] ? undefined : titleId;
24
+ let isRefocusing = (0, $i6df2$useRef)(false);
25
+ // Focus the dialog itself on mount, unless a child element is already focused.
26
+ (0, $i6df2$useEffect)(()=>{
27
+ if (ref.current && !ref.current.contains(document.activeElement)) {
28
+ (0, $i6df2$focusSafely)(ref.current);
29
+ // Safari on iOS does not move the VoiceOver cursor to the dialog
30
+ // or announce that it has opened until it has rendered. A workaround
31
+ // is to wait for half a second, then blur and re-focus the dialog.
32
+ let timeout = setTimeout(()=>{
33
+ if (document.activeElement === ref.current) {
34
+ isRefocusing.current = true;
35
+ if (ref.current) {
36
+ ref.current.blur();
37
+ (0, $i6df2$focusSafely)(ref.current);
38
+ }
39
+ isRefocusing.current = false;
40
+ }
41
+ }, 500);
42
+ return ()=>{
43
+ clearTimeout(timeout);
44
+ };
45
+ }
46
+ }, [
47
+ ref
48
+ ]);
49
+ (0, $i6df2$useOverlayFocusContain)();
50
+ // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused
51
+ // on mount when inside an iframe, no matter which element we programmatically focus.
52
+ // See https://bugs.webkit.org/show_bug.cgi?id=211934.
53
+ // useModal sets aria-hidden on all elements outside the dialog, so the dialog will behave as a modal
54
+ // even without aria-modal on the dialog itself.
55
+ return {
56
+ dialogProps: {
57
+ ...(0, $i6df2$filterDOMProps)(props, {
58
+ labelable: true
59
+ }),
60
+ role: role,
61
+ tabIndex: -1,
62
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
63
+ // Prevent blur events from reaching useOverlay, which may cause
64
+ // popovers to close. Since focus is contained within the dialog,
65
+ // we don't want this to occur due to the above useEffect.
66
+ onBlur: (e)=>{
67
+ if (isRefocusing.current) e.stopPropagation();
68
+ }
69
+ },
70
+ titleProps: {
71
+ id: titleId
72
+ }
73
+ };
74
+ }
75
+
76
+
77
+ export {$40df3f8667284809$export$d55e7ee900f34e93 as useDialog};
78
+ //# sourceMappingURL=useDialog.module.js.map
@@ -0,0 +1 @@
1
+ {"mappings":";;;;;AAAA;;;;;;;;;;CAUC;;;;AAqBM,SAAS,0CAAU,KAAsB,EAAE,GAAuC;IACvF,IAAI,QAAC,OAAO,UAAS,GAAG;IACxB,IAAI,UAA8B,CAAA,GAAA,gBAAQ;IAC1C,UAAU,KAAK,CAAC,aAAa,GAAG,YAAY;IAE5C,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE;IAE1B,+EAA+E;IAC/E,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,IAAI,OAAO,IAAI,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,SAAS,aAAa,GAAG;YAChE,CAAA,GAAA,kBAAU,EAAE,IAAI,OAAO;YAEvB,iEAAiE;YACjE,qEAAqE;YACrE,mEAAmE;YACnE,IAAI,UAAU,WAAW;gBACvB,IAAI,SAAS,aAAa,KAAK,IAAI,OAAO,EAAE;oBAC1C,aAAa,OAAO,GAAG;oBACvB,IAAI,IAAI,OAAO,EAAE;wBACf,IAAI,OAAO,CAAC,IAAI;wBAChB,CAAA,GAAA,kBAAU,EAAE,IAAI,OAAO;oBACzB;oBACA,aAAa,OAAO,GAAG;gBACzB;YACF,GAAG;YAEH,OAAO;gBACL,aAAa;YACf;QACF;IACF,GAAG;QAAC;KAAI;IAER,CAAA,GAAA,6BAAqB;IAErB,sGAAsG;IACtG,qFAAqF;IACrF,sDAAsD;IACtD,qGAAqG;IACrG,gDAAgD;IAChD,OAAO;QACL,aAAa;YACX,GAAG,CAAA,GAAA,qBAAa,EAAE,OAAO;gBAAC,WAAW;YAAI,EAAE;kBAC3C;YACA,UAAU;YACV,mBAAmB,KAAK,CAAC,kBAAkB,IAAI;YAC/C,gEAAgE;YAChE,iEAAiE;YACjE,0DAA0D;YAC1D,QAAQ,CAAA;gBACN,IAAI,aAAa,OAAO,EACtB,EAAE,eAAe;YAErB;QACF;QACA,YAAY;YACV,IAAI;QACN;IACF;AACF","sources":["packages/@react-aria/dialog/src/useDialog.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaDialogProps} from '@react-types/dialog';\nimport {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {filterDOMProps, useSlotId} from '@react-aria/utils';\nimport {focusSafely} from '@react-aria/focus';\nimport {useEffect, useRef} from 'react';\nimport {useOverlayFocusContain} from '@react-aria/overlays';\n\nexport interface DialogAria {\n /** Props for the dialog container element. */\n dialogProps: DOMAttributes,\n\n /** Props for the dialog title element. */\n titleProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a dialog component.\n * A dialog is an overlay shown above other content in an application.\n */\nexport function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElement | null>): DialogAria {\n let {role = 'dialog'} = props;\n let titleId: string | undefined = useSlotId();\n titleId = props['aria-label'] ? undefined : titleId;\n\n let isRefocusing = useRef(false);\n\n // Focus the dialog itself on mount, unless a child element is already focused.\n useEffect(() => {\n if (ref.current && !ref.current.contains(document.activeElement)) {\n focusSafely(ref.current);\n\n // Safari on iOS does not move the VoiceOver cursor to the dialog\n // or announce that it has opened until it has rendered. A workaround\n // is to wait for half a second, then blur and re-focus the dialog.\n let timeout = setTimeout(() => {\n if (document.activeElement === ref.current) {\n isRefocusing.current = true;\n if (ref.current) {\n ref.current.blur();\n focusSafely(ref.current);\n }\n isRefocusing.current = false;\n }\n }, 500);\n\n return () => {\n clearTimeout(timeout);\n };\n }\n }, [ref]);\n\n useOverlayFocusContain();\n\n // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused\n // on mount when inside an iframe, no matter which element we programmatically focus.\n // See https://bugs.webkit.org/show_bug.cgi?id=211934.\n // useModal sets aria-hidden on all elements outside the dialog, so the dialog will behave as a modal\n // even without aria-modal on the dialog itself.\n return {\n dialogProps: {\n ...filterDOMProps(props, {labelable: true}),\n role,\n tabIndex: -1,\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n // Prevent blur events from reaching useOverlay, which may cause\n // popovers to close. Since focus is contained within the dialog,\n // we don't want this to occur due to the above useEffect.\n onBlur: e => {\n if (isRefocusing.current) {\n e.stopPropagation();\n }\n }\n },\n titleProps: {\n id: titleId\n }\n };\n}\n"],"names":[],"version":3,"file":"useDialog.module.js.map"}
package/package.json CHANGED
@@ -1,28 +1,40 @@
1
1
  {
2
2
  "name": "@react-aria/dialog",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-nightly-641446f65-240905",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
7
7
  "module": "dist/module.js",
8
+ "exports": {
9
+ "types": "./dist/types.d.ts",
10
+ "import": "./dist/import.mjs",
11
+ "require": "./dist/main.js"
12
+ },
8
13
  "types": "dist/types.d.ts",
9
14
  "source": "src/index.ts",
10
15
  "files": [
11
- "dist"
16
+ "dist",
17
+ "src"
12
18
  ],
13
19
  "sideEffects": false,
14
20
  "repository": {
15
21
  "type": "git",
16
- "url": "https://github.com/adobe-private/react-spectrum-v3"
22
+ "url": "https://github.com/adobe/react-spectrum"
17
23
  },
18
24
  "peerDependencies": {
19
- "react": "^16.8.0"
25
+ "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0",
26
+ "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0"
20
27
  },
21
28
  "dependencies": {
22
- "@babel/runtime": "^7.6.2"
29
+ "@react-aria/focus": "^3.0.0-nightly-641446f65-240905",
30
+ "@react-aria/overlays": "^3.0.0-nightly-641446f65-240905",
31
+ "@react-aria/utils": "^3.0.0-nightly-641446f65-240905",
32
+ "@react-types/dialog": "^3.0.0-nightly-641446f65-240905",
33
+ "@react-types/shared": "^3.0.0-nightly-641446f65-240905",
34
+ "@swc/helpers": "^0.5.0"
23
35
  },
24
36
  "publishConfig": {
25
37
  "access": "public"
26
38
  },
27
- "gitHead": "5a9784f0bb6c25af7422215efb31ef72caeb9600"
28
- }
39
+ "stableVersion": "3.5.17"
40
+ }
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+ export {useDialog} from './useDialog';
13
+ export type {AriaDialogProps} from '@react-types/dialog';
14
+ export type {DialogAria} from './useDialog';
@@ -0,0 +1,90 @@
1
+ /*
2
+ * Copyright 2020 Adobe. All rights reserved.
3
+ * This file is licensed to you under the Apache License, Version 2.0 (the "License");
4
+ * you may not use this file except in compliance with the License. You may obtain a copy
5
+ * of the License at http://www.apache.org/licenses/LICENSE-2.0
6
+ *
7
+ * Unless required by applicable law or agreed to in writing, software distributed under
8
+ * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
9
+ * OF ANY KIND, either express or implied. See the License for the specific language
10
+ * governing permissions and limitations under the License.
11
+ */
12
+
13
+ import {AriaDialogProps} from '@react-types/dialog';
14
+ import {DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
15
+ import {filterDOMProps, useSlotId} from '@react-aria/utils';
16
+ import {focusSafely} from '@react-aria/focus';
17
+ import {useEffect, useRef} from 'react';
18
+ import {useOverlayFocusContain} from '@react-aria/overlays';
19
+
20
+ export interface DialogAria {
21
+ /** Props for the dialog container element. */
22
+ dialogProps: DOMAttributes,
23
+
24
+ /** Props for the dialog title element. */
25
+ titleProps: DOMAttributes
26
+ }
27
+
28
+ /**
29
+ * Provides the behavior and accessibility implementation for a dialog component.
30
+ * A dialog is an overlay shown above other content in an application.
31
+ */
32
+ export function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElement | null>): DialogAria {
33
+ let {role = 'dialog'} = props;
34
+ let titleId: string | undefined = useSlotId();
35
+ titleId = props['aria-label'] ? undefined : titleId;
36
+
37
+ let isRefocusing = useRef(false);
38
+
39
+ // Focus the dialog itself on mount, unless a child element is already focused.
40
+ useEffect(() => {
41
+ if (ref.current && !ref.current.contains(document.activeElement)) {
42
+ focusSafely(ref.current);
43
+
44
+ // Safari on iOS does not move the VoiceOver cursor to the dialog
45
+ // or announce that it has opened until it has rendered. A workaround
46
+ // is to wait for half a second, then blur and re-focus the dialog.
47
+ let timeout = setTimeout(() => {
48
+ if (document.activeElement === ref.current) {
49
+ isRefocusing.current = true;
50
+ if (ref.current) {
51
+ ref.current.blur();
52
+ focusSafely(ref.current);
53
+ }
54
+ isRefocusing.current = false;
55
+ }
56
+ }, 500);
57
+
58
+ return () => {
59
+ clearTimeout(timeout);
60
+ };
61
+ }
62
+ }, [ref]);
63
+
64
+ useOverlayFocusContain();
65
+
66
+ // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused
67
+ // on mount when inside an iframe, no matter which element we programmatically focus.
68
+ // See https://bugs.webkit.org/show_bug.cgi?id=211934.
69
+ // useModal sets aria-hidden on all elements outside the dialog, so the dialog will behave as a modal
70
+ // even without aria-modal on the dialog itself.
71
+ return {
72
+ dialogProps: {
73
+ ...filterDOMProps(props, {labelable: true}),
74
+ role,
75
+ tabIndex: -1,
76
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
77
+ // Prevent blur events from reaching useOverlay, which may cause
78
+ // popovers to close. Since focus is contained within the dialog,
79
+ // we don't want this to occur due to the above useEffect.
80
+ onBlur: e => {
81
+ if (isRefocusing.current) {
82
+ e.stopPropagation();
83
+ }
84
+ }
85
+ },
86
+ titleProps: {
87
+ id: titleId
88
+ }
89
+ };
90
+ }