@react-aria/dialog 3.3.1 → 3.4.1

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/dist/main.js CHANGED
@@ -1,6 +1,7 @@
1
1
  var $6vrKB$reactariautils = require("@react-aria/utils");
2
2
  var $6vrKB$reactariafocus = require("@react-aria/focus");
3
3
  var $6vrKB$react = require("react");
4
+ var $6vrKB$reactariaoverlays = require("@react-aria/overlays");
4
5
 
5
6
  function $parcel$export(e, n, v, s) {
6
7
  Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
@@ -10,10 +11,12 @@ $parcel$export(module.exports, "useDialog", () => $e7b76b4fae4e4c55$export$d55e7
10
11
 
11
12
 
12
13
 
14
+
13
15
  function $e7b76b4fae4e4c55$export$d55e7ee900f34e93(props, ref) {
14
16
  let { role: role = 'dialog' } = props;
15
17
  let titleId = $6vrKB$reactariautils.useSlotId();
16
18
  titleId = props['aria-label'] ? undefined : titleId;
19
+ let isRefocusing = $6vrKB$react.useRef(false);
17
20
  // Focus the dialog itself on mount, unless a child element is already focused.
18
21
  $6vrKB$react.useEffect(()=>{
19
22
  if (ref.current && !ref.current.contains(document.activeElement)) {
@@ -23,8 +26,10 @@ function $e7b76b4fae4e4c55$export$d55e7ee900f34e93(props, ref) {
23
26
  // is to wait for half a second, then blur and re-focus the dialog.
24
27
  let timeout = setTimeout(()=>{
25
28
  if (document.activeElement === ref.current) {
29
+ isRefocusing.current = true;
26
30
  ref.current.blur();
27
31
  $6vrKB$reactariafocus.focusSafely(ref.current);
32
+ isRefocusing.current = false;
28
33
  }
29
34
  }, 500);
30
35
  return ()=>{
@@ -34,6 +39,7 @@ function $e7b76b4fae4e4c55$export$d55e7ee900f34e93(props, ref) {
34
39
  }, [
35
40
  ref
36
41
  ]);
42
+ $6vrKB$reactariaoverlays.useOverlayFocusContain();
37
43
  // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused
38
44
  // on mount when inside an iframe, no matter which element we programmatically focus.
39
45
  // See https://bugs.webkit.org/show_bug.cgi?id=211934.
@@ -46,7 +52,13 @@ function $e7b76b4fae4e4c55$export$d55e7ee900f34e93(props, ref) {
46
52
  }),
47
53
  role: role,
48
54
  tabIndex: -1,
49
- 'aria-labelledby': props['aria-labelledby'] || titleId
55
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
56
+ // Prevent blur events from reaching useOverlay, which may cause
57
+ // popovers to close. Since focus is contained within the dialog,
58
+ // we don't want this to occur due to the above useEffect.
59
+ onBlur: (e)=>{
60
+ if (isRefocusing.current) e.stopPropagation();
61
+ }
50
62
  },
51
63
  titleProps: {
52
64
  id: titleId
package/dist/main.js.map CHANGED
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;SC8BgB,yCAAS,CAAC,KAAsB,EAAE,GAAgC,EAAc,CAAC;IAC/F,GAAG,CAAC,CAAC,OAAA,IAAI,GAAG,CAAQ,SAAA,CAAC,GAAG,KAAK;IAC7B,GAAG,CAAC,OAAO,GAAG,+BAAS;IACvB,OAAO,GAAG,KAAK,CAAC,CAAY,eAAI,SAAS,GAAG,OAAO;IAEnD,EAA+E,AAA/E,6EAA+E;IAC/E,sBAAS,KAAO,CAAC;QACf,EAAE,EAAE,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,GAAG,CAAC;YACjE,iCAAW,CAAC,GAAG,CAAC,OAAO;YAEvB,EAAiE,AAAjE,+DAAiE;YACjE,EAAqE,AAArE,mEAAqE;YACrE,EAAmE,AAAnE,iEAAmE;YACnE,GAAG,CAAC,OAAO,GAAG,UAAU,KAAO,CAAC;gBAC9B,EAAE,EAAE,QAAQ,CAAC,aAAa,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;oBAC3C,GAAG,CAAC,OAAO,CAAC,IAAI;oBAChB,iCAAW,CAAC,GAAG,CAAC,OAAO;gBACzB,CAAC;YACH,CAAC,EAAE,GAAG;YAEN,MAAM,KAAO,CAAC;gBACZ,YAAY,CAAC,OAAO;YACtB,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC;QAAA,GAAG;IAAA,CAAC;IAER,EAAsG,AAAtG,oGAAsG;IACtG,EAAqF,AAArF,mFAAqF;IACrF,EAAsD,AAAtD,oDAAsD;IACtD,EAAqG,AAArG,mGAAqG;IACrG,EAAgD,AAAhD,8CAAgD;IAChD,MAAM,CAAC,CAAC;QACN,WAAW,EAAE,CAAC;eACT,oCAAc,CAAC,KAAK,EAAE,CAAC;gBAAA,SAAS,EAAE,IAAI;YAAA,CAAC;kBAC1C,IAAI;YACJ,QAAQ,EAAE,EAAE;YACZ,CAAiB,kBAAE,KAAK,CAAC,CAAiB,qBAAK,OAAO;QACxD,CAAC;QACD,UAAU,EAAE,CAAC;YACX,EAAE,EAAE,OAAO;QACb,CAAC;IACH,CAAC;AACH,CAAC","sources":["packages/@react-aria/dialog/src/index.ts","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 */\nexport {useDialog} from './useDialog';\nexport type {AriaDialogProps} from '@react-types/dialog';\nexport type {DialogAria} from './useDialog';\n","/*\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} from '@react-types/shared';\nimport {filterDOMProps, useSlotId} from '@react-aria/utils';\nimport {focusSafely} from '@react-aria/focus';\nimport {RefObject, useEffect} from 'react';\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>): DialogAria {\n let {role = 'dialog'} = props;\n let titleId = useSlotId();\n titleId = props['aria-label'] ? undefined : titleId;\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 ref.current.blur();\n focusSafely(ref.current);\n }\n }, 500);\n\n return () => {\n clearTimeout(timeout);\n };\n }\n }, [ref]);\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 },\n titleProps: {\n id: titleId\n }\n };\n}\n"],"names":[],"version":3,"file":"main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;SC+BgB,yCAAS,CAAC,KAAsB,EAAE,GAAgC,EAAc,CAAC;IAC/F,GAAG,CAAC,CAAC,OAAA,IAAI,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CAAiB,kBAAE,KAAK,CAAC,CAAiB,qBAAK,OAAO;YACtD,EAAgE,AAAhE,8DAAgE;YAChE,EAAiE,AAAjE,+DAAiE;YACjE,EAA0D,AAA1D,wDAA0D;YAC1D,MAAM,GAAE,CAAC,GAAI,CAAC;gBACZ,EAAE,EAAE,YAAY,CAAC,OAAO,EACtB,CAAC,CAAC,eAAe;YAErB,CAAC;QACH,CAAC;QACD,UAAU,EAAE,CAAC;YACX,EAAE,EAAE,OAAO;QACb,CAAC;IACH,CAAC;AACH,CAAC","sources":["packages/@react-aria/dialog/src/index.ts","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 */\nexport {useDialog} from './useDialog';\nexport type {AriaDialogProps} from '@react-types/dialog';\nexport type {DialogAria} from './useDialog';\n","/*\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} from '@react-types/shared';\nimport {filterDOMProps, useSlotId} from '@react-aria/utils';\nimport {focusSafely} from '@react-aria/focus';\nimport {RefObject, 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>): DialogAria {\n let {role = 'dialog'} = props;\n let titleId = 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 ref.current.blur();\n focusSafely(ref.current);\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":"main.js.map"}
package/dist/module.js CHANGED
@@ -1,6 +1,8 @@
1
1
  import {useSlotId as $m1DSs$useSlotId, filterDOMProps as $m1DSs$filterDOMProps} from "@react-aria/utils";
2
2
  import {focusSafely as $m1DSs$focusSafely} from "@react-aria/focus";
3
- import {useEffect as $m1DSs$useEffect} from "react";
3
+ import {useRef as $m1DSs$useRef, useEffect as $m1DSs$useEffect} from "react";
4
+ import {useOverlayFocusContain as $m1DSs$useOverlayFocusContain} from "@react-aria/overlays";
5
+
4
6
 
5
7
 
6
8
 
@@ -9,6 +11,7 @@ function $40df3f8667284809$export$d55e7ee900f34e93(props, ref) {
9
11
  let { role: role = 'dialog' } = props;
10
12
  let titleId = $m1DSs$useSlotId();
11
13
  titleId = props['aria-label'] ? undefined : titleId;
14
+ let isRefocusing = $m1DSs$useRef(false);
12
15
  // Focus the dialog itself on mount, unless a child element is already focused.
13
16
  $m1DSs$useEffect(()=>{
14
17
  if (ref.current && !ref.current.contains(document.activeElement)) {
@@ -18,8 +21,10 @@ function $40df3f8667284809$export$d55e7ee900f34e93(props, ref) {
18
21
  // is to wait for half a second, then blur and re-focus the dialog.
19
22
  let timeout = setTimeout(()=>{
20
23
  if (document.activeElement === ref.current) {
24
+ isRefocusing.current = true;
21
25
  ref.current.blur();
22
26
  $m1DSs$focusSafely(ref.current);
27
+ isRefocusing.current = false;
23
28
  }
24
29
  }, 500);
25
30
  return ()=>{
@@ -29,6 +34,7 @@ function $40df3f8667284809$export$d55e7ee900f34e93(props, ref) {
29
34
  }, [
30
35
  ref
31
36
  ]);
37
+ $m1DSs$useOverlayFocusContain();
32
38
  // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused
33
39
  // on mount when inside an iframe, no matter which element we programmatically focus.
34
40
  // See https://bugs.webkit.org/show_bug.cgi?id=211934.
@@ -41,7 +47,13 @@ function $40df3f8667284809$export$d55e7ee900f34e93(props, ref) {
41
47
  }),
42
48
  role: role,
43
49
  tabIndex: -1,
44
- 'aria-labelledby': props['aria-labelledby'] || titleId
50
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
51
+ // Prevent blur events from reaching useOverlay, which may cause
52
+ // popovers to close. Since focus is contained within the dialog,
53
+ // we don't want this to occur due to the above useEffect.
54
+ onBlur: (e)=>{
55
+ if (isRefocusing.current) e.stopPropagation();
56
+ }
45
57
  },
46
58
  titleProps: {
47
59
  id: titleId
@@ -1 +1 @@
1
- {"mappings":";;;;;;;SC8BgB,yCAAS,CAAC,KAAsB,EAAE,GAAgC,EAAc,CAAC;IAC/F,GAAG,CAAC,CAAC,OAAA,IAAI,GAAG,CAAQ,SAAA,CAAC,GAAG,KAAK;IAC7B,GAAG,CAAC,OAAO,GAAG,gBAAS;IACvB,OAAO,GAAG,KAAK,CAAC,CAAY,eAAI,SAAS,GAAG,OAAO;IAEnD,EAA+E,AAA/E,6EAA+E;IAC/E,gBAAS,KAAO,CAAC;QACf,EAAE,EAAE,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,GAAG,CAAC;YACjE,kBAAW,CAAC,GAAG,CAAC,OAAO;YAEvB,EAAiE,AAAjE,+DAAiE;YACjE,EAAqE,AAArE,mEAAqE;YACrE,EAAmE,AAAnE,iEAAmE;YACnE,GAAG,CAAC,OAAO,GAAG,UAAU,KAAO,CAAC;gBAC9B,EAAE,EAAE,QAAQ,CAAC,aAAa,KAAK,GAAG,CAAC,OAAO,EAAE,CAAC;oBAC3C,GAAG,CAAC,OAAO,CAAC,IAAI;oBAChB,kBAAW,CAAC,GAAG,CAAC,OAAO;gBACzB,CAAC;YACH,CAAC,EAAE,GAAG;YAEN,MAAM,KAAO,CAAC;gBACZ,YAAY,CAAC,OAAO;YACtB,CAAC;QACH,CAAC;IACH,CAAC,EAAE,CAAC;QAAA,GAAG;IAAA,CAAC;IAER,EAAsG,AAAtG,oGAAsG;IACtG,EAAqF,AAArF,mFAAqF;IACrF,EAAsD,AAAtD,oDAAsD;IACtD,EAAqG,AAArG,mGAAqG;IACrG,EAAgD,AAAhD,8CAAgD;IAChD,MAAM,CAAC,CAAC;QACN,WAAW,EAAE,CAAC;eACT,qBAAc,CAAC,KAAK,EAAE,CAAC;gBAAA,SAAS,EAAE,IAAI;YAAA,CAAC;kBAC1C,IAAI;YACJ,QAAQ,EAAE,EAAE;YACZ,CAAiB,kBAAE,KAAK,CAAC,CAAiB,qBAAK,OAAO;QACxD,CAAC;QACD,UAAU,EAAE,CAAC;YACX,EAAE,EAAE,OAAO;QACb,CAAC;IACH,CAAC;AACH,CAAC","sources":["packages/@react-aria/dialog/src/index.ts","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 */\nexport {useDialog} from './useDialog';\nexport type {AriaDialogProps} from '@react-types/dialog';\nexport type {DialogAria} from './useDialog';\n","/*\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} from '@react-types/shared';\nimport {filterDOMProps, useSlotId} from '@react-aria/utils';\nimport {focusSafely} from '@react-aria/focus';\nimport {RefObject, useEffect} from 'react';\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>): DialogAria {\n let {role = 'dialog'} = props;\n let titleId = useSlotId();\n titleId = props['aria-label'] ? undefined : titleId;\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 ref.current.blur();\n focusSafely(ref.current);\n }\n }, 500);\n\n return () => {\n clearTimeout(timeout);\n };\n }\n }, [ref]);\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 },\n titleProps: {\n id: titleId\n }\n };\n}\n"],"names":[],"version":3,"file":"module.js.map"}
1
+ {"mappings":";;;;;;;;;SC+BgB,yCAAS,CAAC,KAAsB,EAAE,GAAgC,EAAc,CAAC;IAC/F,GAAG,CAAC,CAAC,OAAA,IAAI,GAAG,CAAQ,SAAA,CAAC,GAAG,KAAK;IAC7B,GAAG,CAAC,OAAO,GAAG,gBAAS;IACvB,OAAO,GAAG,KAAK,CAAC,CAAY,eAAI,SAAS,GAAG,OAAO;IAEnD,GAAG,CAAC,YAAY,GAAG,aAAM,CAAC,KAAK;IAE/B,EAA+E,AAA/E,6EAA+E;IAC/E,gBAAS,KAAO,CAAC;QACf,EAAE,EAAE,GAAG,CAAC,OAAO,KAAK,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC,QAA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H,CAAC","sources":["packages/@react-aria/dialog/src/index.ts","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 */\nexport {useDialog} from './useDialog';\nexport type {AriaDialogProps} from '@react-types/dialog';\nexport type {DialogAria} from './useDialog';\n","/*\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} from '@react-types/shared';\nimport {filterDOMProps, useSlotId} from '@react-aria/utils';\nimport {focusSafely} from '@react-aria/focus';\nimport {RefObject, 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>): DialogAria {\n let {role = 'dialog'} = props;\n let titleId = 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 ref.current.blur();\n focusSafely(ref.current);\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":"module.js.map"}
@@ -1 +1 @@
1
- {"mappings":";;;AAkBA;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,CAAC,GAAG,UAAU,CA0C9F;AC5DD,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"}
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,CAAC,GAAG,UAAU,CAwD9F;AC3ED,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/dialog",
3
- "version": "3.3.1",
3
+ "version": "3.4.1",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -21,14 +21,15 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@babel/runtime": "^7.6.2",
24
- "@react-aria/focus": "^3.8.0",
25
- "@react-aria/utils": "^3.13.3",
26
- "@react-stately/overlays": "^3.4.1",
27
- "@react-types/dialog": "^3.4.3",
28
- "@react-types/shared": "^3.14.1"
24
+ "@react-aria/focus": "^3.10.0",
25
+ "@react-aria/overlays": "^3.12.0",
26
+ "@react-aria/utils": "^3.14.1",
27
+ "@react-stately/overlays": "^3.4.3",
28
+ "@react-types/dialog": "^3.4.5",
29
+ "@react-types/shared": "^3.16.0"
29
30
  },
30
31
  "publishConfig": {
31
32
  "access": "public"
32
33
  },
33
- "gitHead": "b03ef51e6317547dd0a840f151e59d039b1e1fd3"
34
+ "gitHead": "2954307ddbefe149241685440c81f80ece6b2c83"
34
35
  }
package/src/useDialog.ts CHANGED
@@ -14,7 +14,8 @@ import {AriaDialogProps} from '@react-types/dialog';
14
14
  import {DOMAttributes, FocusableElement} from '@react-types/shared';
15
15
  import {filterDOMProps, useSlotId} from '@react-aria/utils';
16
16
  import {focusSafely} from '@react-aria/focus';
17
- import {RefObject, useEffect} from 'react';
17
+ import {RefObject, useEffect, useRef} from 'react';
18
+ import {useOverlayFocusContain} from '@react-aria/overlays';
18
19
 
19
20
  export interface DialogAria {
20
21
  /** Props for the dialog container element. */
@@ -33,6 +34,8 @@ export function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElemen
33
34
  let titleId = useSlotId();
34
35
  titleId = props['aria-label'] ? undefined : titleId;
35
36
 
37
+ let isRefocusing = useRef(false);
38
+
36
39
  // Focus the dialog itself on mount, unless a child element is already focused.
37
40
  useEffect(() => {
38
41
  if (ref.current && !ref.current.contains(document.activeElement)) {
@@ -43,8 +46,10 @@ export function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElemen
43
46
  // is to wait for half a second, then blur and re-focus the dialog.
44
47
  let timeout = setTimeout(() => {
45
48
  if (document.activeElement === ref.current) {
49
+ isRefocusing.current = true;
46
50
  ref.current.blur();
47
51
  focusSafely(ref.current);
52
+ isRefocusing.current = false;
48
53
  }
49
54
  }, 500);
50
55
 
@@ -54,6 +59,8 @@ export function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElemen
54
59
  }
55
60
  }, [ref]);
56
61
 
62
+ useOverlayFocusContain();
63
+
57
64
  // We do not use aria-modal due to a Safari bug which forces the first focusable element to be focused
58
65
  // on mount when inside an iframe, no matter which element we programmatically focus.
59
66
  // See https://bugs.webkit.org/show_bug.cgi?id=211934.
@@ -64,7 +71,15 @@ export function useDialog(props: AriaDialogProps, ref: RefObject<FocusableElemen
64
71
  ...filterDOMProps(props, {labelable: true}),
65
72
  role,
66
73
  tabIndex: -1,
67
- 'aria-labelledby': props['aria-labelledby'] || titleId
74
+ 'aria-labelledby': props['aria-labelledby'] || titleId,
75
+ // Prevent blur events from reaching useOverlay, which may cause
76
+ // popovers to close. Since focus is contained within the dialog,
77
+ // we don't want this to occur due to the above useEffect.
78
+ onBlur: e => {
79
+ if (isRefocusing.current) {
80
+ e.stopPropagation();
81
+ }
82
+ }
68
83
  },
69
84
  titleProps: {
70
85
  id: titleId