@react-aria/toast 3.0.0-beta.12 → 3.0.0-beta.14

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 (185) hide show
  1. package/dist/ar-AE.main.js +4 -1
  2. package/dist/ar-AE.main.js.map +1 -1
  3. package/dist/ar-AE.mjs +4 -1
  4. package/dist/ar-AE.module.js +4 -1
  5. package/dist/ar-AE.module.js.map +1 -1
  6. package/dist/bg-BG.main.js +4 -1
  7. package/dist/bg-BG.main.js.map +1 -1
  8. package/dist/bg-BG.mjs +4 -1
  9. package/dist/bg-BG.module.js +4 -1
  10. package/dist/bg-BG.module.js.map +1 -1
  11. package/dist/cs-CZ.main.js +4 -1
  12. package/dist/cs-CZ.main.js.map +1 -1
  13. package/dist/cs-CZ.mjs +4 -1
  14. package/dist/cs-CZ.module.js +4 -1
  15. package/dist/cs-CZ.module.js.map +1 -1
  16. package/dist/da-DK.main.js +4 -1
  17. package/dist/da-DK.main.js.map +1 -1
  18. package/dist/da-DK.mjs +4 -1
  19. package/dist/da-DK.module.js +4 -1
  20. package/dist/da-DK.module.js.map +1 -1
  21. package/dist/de-DE.main.js +4 -1
  22. package/dist/de-DE.main.js.map +1 -1
  23. package/dist/de-DE.mjs +4 -1
  24. package/dist/de-DE.module.js +4 -1
  25. package/dist/de-DE.module.js.map +1 -1
  26. package/dist/el-GR.main.js +4 -1
  27. package/dist/el-GR.main.js.map +1 -1
  28. package/dist/el-GR.mjs +4 -1
  29. package/dist/el-GR.module.js +4 -1
  30. package/dist/el-GR.module.js.map +1 -1
  31. package/dist/en-US.main.js +4 -1
  32. package/dist/en-US.main.js.map +1 -1
  33. package/dist/en-US.mjs +4 -1
  34. package/dist/en-US.module.js +4 -1
  35. package/dist/en-US.module.js.map +1 -1
  36. package/dist/es-ES.main.js +4 -1
  37. package/dist/es-ES.main.js.map +1 -1
  38. package/dist/es-ES.mjs +4 -1
  39. package/dist/es-ES.module.js +4 -1
  40. package/dist/es-ES.module.js.map +1 -1
  41. package/dist/et-EE.main.js +4 -1
  42. package/dist/et-EE.main.js.map +1 -1
  43. package/dist/et-EE.mjs +4 -1
  44. package/dist/et-EE.module.js +4 -1
  45. package/dist/et-EE.module.js.map +1 -1
  46. package/dist/fi-FI.main.js +4 -1
  47. package/dist/fi-FI.main.js.map +1 -1
  48. package/dist/fi-FI.mjs +4 -1
  49. package/dist/fi-FI.module.js +4 -1
  50. package/dist/fi-FI.module.js.map +1 -1
  51. package/dist/fr-FR.main.js +4 -1
  52. package/dist/fr-FR.main.js.map +1 -1
  53. package/dist/fr-FR.mjs +4 -1
  54. package/dist/fr-FR.module.js +4 -1
  55. package/dist/fr-FR.module.js.map +1 -1
  56. package/dist/he-IL.main.js +4 -1
  57. package/dist/he-IL.main.js.map +1 -1
  58. package/dist/he-IL.mjs +4 -1
  59. package/dist/he-IL.module.js +4 -1
  60. package/dist/he-IL.module.js.map +1 -1
  61. package/dist/hr-HR.main.js +4 -1
  62. package/dist/hr-HR.main.js.map +1 -1
  63. package/dist/hr-HR.mjs +4 -1
  64. package/dist/hr-HR.module.js +4 -1
  65. package/dist/hr-HR.module.js.map +1 -1
  66. package/dist/hu-HU.main.js +4 -1
  67. package/dist/hu-HU.main.js.map +1 -1
  68. package/dist/hu-HU.mjs +4 -1
  69. package/dist/hu-HU.module.js +4 -1
  70. package/dist/hu-HU.module.js.map +1 -1
  71. package/dist/it-IT.main.js +4 -1
  72. package/dist/it-IT.main.js.map +1 -1
  73. package/dist/it-IT.mjs +4 -1
  74. package/dist/it-IT.module.js +4 -1
  75. package/dist/it-IT.module.js.map +1 -1
  76. package/dist/ja-JP.main.js +4 -1
  77. package/dist/ja-JP.main.js.map +1 -1
  78. package/dist/ja-JP.mjs +4 -1
  79. package/dist/ja-JP.module.js +4 -1
  80. package/dist/ja-JP.module.js.map +1 -1
  81. package/dist/ko-KR.main.js +4 -1
  82. package/dist/ko-KR.main.js.map +1 -1
  83. package/dist/ko-KR.mjs +4 -1
  84. package/dist/ko-KR.module.js +4 -1
  85. package/dist/ko-KR.module.js.map +1 -1
  86. package/dist/lt-LT.main.js +4 -1
  87. package/dist/lt-LT.main.js.map +1 -1
  88. package/dist/lt-LT.mjs +4 -1
  89. package/dist/lt-LT.module.js +4 -1
  90. package/dist/lt-LT.module.js.map +1 -1
  91. package/dist/lv-LV.main.js +4 -1
  92. package/dist/lv-LV.main.js.map +1 -1
  93. package/dist/lv-LV.mjs +4 -1
  94. package/dist/lv-LV.module.js +4 -1
  95. package/dist/lv-LV.module.js.map +1 -1
  96. package/dist/nb-NO.main.js +4 -1
  97. package/dist/nb-NO.main.js.map +1 -1
  98. package/dist/nb-NO.mjs +4 -1
  99. package/dist/nb-NO.module.js +4 -1
  100. package/dist/nb-NO.module.js.map +1 -1
  101. package/dist/nl-NL.main.js +4 -1
  102. package/dist/nl-NL.main.js.map +1 -1
  103. package/dist/nl-NL.mjs +4 -1
  104. package/dist/nl-NL.module.js +4 -1
  105. package/dist/nl-NL.module.js.map +1 -1
  106. package/dist/pl-PL.main.js +6 -1
  107. package/dist/pl-PL.main.js.map +1 -1
  108. package/dist/pl-PL.mjs +6 -1
  109. package/dist/pl-PL.module.js +6 -1
  110. package/dist/pl-PL.module.js.map +1 -1
  111. package/dist/pt-BR.main.js +4 -1
  112. package/dist/pt-BR.main.js.map +1 -1
  113. package/dist/pt-BR.mjs +4 -1
  114. package/dist/pt-BR.module.js +4 -1
  115. package/dist/pt-BR.module.js.map +1 -1
  116. package/dist/pt-PT.main.js +4 -1
  117. package/dist/pt-PT.main.js.map +1 -1
  118. package/dist/pt-PT.mjs +4 -1
  119. package/dist/pt-PT.module.js +4 -1
  120. package/dist/pt-PT.module.js.map +1 -1
  121. package/dist/ro-RO.main.js +4 -1
  122. package/dist/ro-RO.main.js.map +1 -1
  123. package/dist/ro-RO.mjs +4 -1
  124. package/dist/ro-RO.module.js +4 -1
  125. package/dist/ro-RO.module.js.map +1 -1
  126. package/dist/ru-RU.main.js +4 -1
  127. package/dist/ru-RU.main.js.map +1 -1
  128. package/dist/ru-RU.mjs +4 -1
  129. package/dist/ru-RU.module.js +4 -1
  130. package/dist/ru-RU.module.js.map +1 -1
  131. package/dist/sk-SK.main.js +5 -1
  132. package/dist/sk-SK.main.js.map +1 -1
  133. package/dist/sk-SK.mjs +5 -1
  134. package/dist/sk-SK.module.js +5 -1
  135. package/dist/sk-SK.module.js.map +1 -1
  136. package/dist/sl-SI.main.js +6 -1
  137. package/dist/sl-SI.main.js.map +1 -1
  138. package/dist/sl-SI.mjs +6 -1
  139. package/dist/sl-SI.module.js +6 -1
  140. package/dist/sl-SI.module.js.map +1 -1
  141. package/dist/sr-SP.main.js +4 -1
  142. package/dist/sr-SP.main.js.map +1 -1
  143. package/dist/sr-SP.mjs +4 -1
  144. package/dist/sr-SP.module.js +4 -1
  145. package/dist/sr-SP.module.js.map +1 -1
  146. package/dist/sv-SE.main.js +4 -1
  147. package/dist/sv-SE.main.js.map +1 -1
  148. package/dist/sv-SE.mjs +4 -1
  149. package/dist/sv-SE.module.js +4 -1
  150. package/dist/sv-SE.module.js.map +1 -1
  151. package/dist/tr-TR.main.js +4 -1
  152. package/dist/tr-TR.main.js.map +1 -1
  153. package/dist/tr-TR.mjs +4 -1
  154. package/dist/tr-TR.module.js +4 -1
  155. package/dist/tr-TR.module.js.map +1 -1
  156. package/dist/types.d.ts +6 -5
  157. package/dist/types.d.ts.map +1 -1
  158. package/dist/uk-UA.main.js +4 -1
  159. package/dist/uk-UA.main.js.map +1 -1
  160. package/dist/uk-UA.mjs +4 -1
  161. package/dist/uk-UA.module.js +4 -1
  162. package/dist/uk-UA.module.js.map +1 -1
  163. package/dist/useToast.main.js +14 -22
  164. package/dist/useToast.main.js.map +1 -1
  165. package/dist/useToast.mjs +16 -24
  166. package/dist/useToast.module.js +16 -24
  167. package/dist/useToast.module.js.map +1 -1
  168. package/dist/useToastRegion.main.js +85 -6
  169. package/dist/useToastRegion.main.js.map +1 -1
  170. package/dist/useToastRegion.mjs +86 -7
  171. package/dist/useToastRegion.module.js +86 -7
  172. package/dist/useToastRegion.module.js.map +1 -1
  173. package/dist/zh-CN.main.js +4 -1
  174. package/dist/zh-CN.main.js.map +1 -1
  175. package/dist/zh-CN.mjs +4 -1
  176. package/dist/zh-CN.module.js +4 -1
  177. package/dist/zh-CN.module.js.map +1 -1
  178. package/dist/zh-TW.main.js +4 -1
  179. package/dist/zh-TW.main.js.map +1 -1
  180. package/dist/zh-TW.mjs +4 -1
  181. package/dist/zh-TW.module.js +4 -1
  182. package/dist/zh-TW.module.js.map +1 -1
  183. package/package.json +10 -10
  184. package/src/useToast.ts +24 -30
  185. package/src/useToastRegion.ts +98 -10
@@ -1,6 +1,6 @@
1
1
  import $7WpW4$intlStringsmodulejs from "./intlStrings.module.js";
2
- import {useEffect as $7WpW4$useEffect, useRef as $7WpW4$useRef} from "react";
3
- import {useLayoutEffect as $7WpW4$useLayoutEffect, useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId} from "@react-aria/utils";
2
+ import $7WpW4$react, {useEffect as $7WpW4$useEffect} from "react";
3
+ import {useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId} from "@react-aria/utils";
4
4
  import {useLocalizedStringFormatter as $7WpW4$useLocalizedStringFormatter} from "@react-aria/i18n";
5
5
 
6
6
 
@@ -33,41 +33,33 @@ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
33
33
  timer,
34
34
  timeout
35
35
  ]);
36
- // Restore focus to the toast container on unmount.
37
- // If there are no more toasts, the container will be unmounted
38
- // and will restore focus to wherever focus was before the user
39
- // focused the toast region.
40
- let focusOnUnmount = (0, $7WpW4$useRef)(null);
41
- (0, $7WpW4$useLayoutEffect)(()=>{
42
- let container = ref.current.closest('[role=region]');
43
- return ()=>{
44
- if (container && container.contains(document.activeElement)) // Focus must be delayed for focus ring to appear, but we can't wait
45
- // until useEffect cleanup to check if focus was inside the container.
46
- focusOnUnmount.current = container;
47
- };
48
- }, [
49
- ref
50
- ]);
51
- // eslint-disable-next-line
36
+ let [isEntered, setIsEntered] = (0, $7WpW4$react).useState(false);
52
37
  (0, $7WpW4$useEffect)(()=>{
53
- return ()=>{
54
- if (focusOnUnmount.current) focusOnUnmount.current.focus();
55
- };
38
+ if (animation === 'entering' || animation === 'queued') setIsEntered(true);
56
39
  }, [
57
- ref
40
+ animation
58
41
  ]);
59
42
  let titleId = (0, $7WpW4$useId)();
60
43
  let descriptionId = (0, $7WpW4$useSlotId)();
61
44
  let stringFormatter = (0, $7WpW4$useLocalizedStringFormatter)((0, ($parcel$interopDefault($7WpW4$intlStringsmodulejs))), '@react-aria/toast');
62
45
  return {
63
46
  toastProps: {
64
- role: 'alert',
47
+ role: 'alertdialog',
48
+ 'aria-modal': 'false',
65
49
  'aria-label': props['aria-label'],
66
50
  'aria-labelledby': props['aria-labelledby'] || titleId,
67
51
  'aria-describedby': props['aria-describedby'] || descriptionId,
68
52
  'aria-details': props['aria-details'],
69
53
  // Hide toasts that are animating out so VoiceOver doesn't announce them.
70
- 'aria-hidden': animation === 'exiting' ? 'true' : undefined
54
+ 'aria-hidden': animation === 'exiting' ? 'true' : undefined,
55
+ tabIndex: 0
56
+ },
57
+ contentProps: {
58
+ role: 'alert',
59
+ 'aria-atomic': 'true',
60
+ style: {
61
+ visibility: isEntered || animation === null ? 'visible' : 'hidden'
62
+ }
71
63
  },
72
64
  titleProps: {
73
65
  id: titleId
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AA+BM,SAAS,0CAAY,KAAwB,EAAE,KAAoB,EAAE,GAAgC;IAC1G,IAAI,OACF,GAAG,SACH,KAAK,WACL,OAAO,aACP,SAAS,EACV,GAAG,MAAM,KAAK;IAEf,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,CAAC,OACH;QAGF,MAAM,KAAK,CAAC;QACZ,OAAO;YACL,MAAM,KAAK;QACb;IACF,GAAG;QAAC;QAAO;KAAQ;IAEnB,mDAAmD;IACnD,+DAA+D;IAC/D,+DAA+D;IAC/D,4BAA4B;IAC5B,IAAI,iBAAiB,CAAA,GAAA,aAAK,EAAE;IAC5B,CAAA,GAAA,sBAAc,EAAE;QACd,IAAI,YAAY,IAAI,OAAO,CAAC,OAAO,CAAC;QACpC,OAAO;YACL,IAAI,aAAa,UAAU,QAAQ,CAAC,SAAS,aAAa,GACxD,oEAAoE;YACpE,sEAAsE;YACtE,eAAe,OAAO,GAAG;QAE7B;IACF,GAAG;QAAC;KAAI;IAER,2BAA2B;IAC3B,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO;YACL,IAAI,eAAe,OAAO,EACxB,eAAe,OAAO,CAAC,KAAK;QAEhC;IACF,GAAG;QAAC;KAAI;IAER,IAAI,UAAU,CAAA,GAAA,YAAI;IAClB,IAAI,gBAAgB,CAAA,GAAA,gBAAQ;IAC5B,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAEhE,OAAO;QACL,YAAY;YACV,MAAM;YACN,cAAc,KAAK,CAAC,aAAa;YACjC,mBAAmB,KAAK,CAAC,kBAAkB,IAAI;YAC/C,oBAAoB,KAAK,CAAC,mBAAmB,IAAI;YACjD,gBAAgB,KAAK,CAAC,eAAe;YACrC,yEAAyE;YACzE,eAAe,cAAc,YAAY,SAAS;QACpD;QACA,YAAY;YACV,IAAI;QACN;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,kBAAkB;YAChB,cAAc,gBAAgB,MAAM,CAAC;YACrC,SAAS,IAAM,MAAM,KAAK,CAAC;QAC7B;IACF;AACF","sources":["packages/@react-aria/toast/src/useToast.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaLabelingProps, DOMAttributes, FocusableElement} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {useId, useLayoutEffect, useSlotId} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastProps<T> extends AriaLabelingProps {\n /** The toast object. */\n toast: QueuedToast<T>\n}\n\nexport interface ToastAria {\n /** Props for the toast container element. */\n toastProps: DOMAttributes,\n /** Props for the toast title element. */\n titleProps: DOMAttributes,\n /** Props for the toast description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the toast close button. */\n closeButtonProps: AriaButtonProps\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast component.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement>): ToastAria {\n let {\n key,\n timer,\n timeout,\n animation\n } = props.toast;\n\n useEffect(() => {\n if (!timer) {\n return;\n }\n\n timer.reset(timeout);\n return () => {\n timer.pause();\n };\n }, [timer, timeout]);\n\n // Restore focus to the toast container on unmount.\n // If there are no more toasts, the container will be unmounted\n // and will restore focus to wherever focus was before the user\n // focused the toast region.\n let focusOnUnmount = useRef(null);\n useLayoutEffect(() => {\n let container = ref.current.closest('[role=region]') as HTMLElement;\n return () => {\n if (container && container.contains(document.activeElement)) {\n // Focus must be delayed for focus ring to appear, but we can't wait\n // until useEffect cleanup to check if focus was inside the container.\n focusOnUnmount.current = container;\n }\n };\n }, [ref]);\n\n // eslint-disable-next-line\n useEffect(() => {\n return () => {\n if (focusOnUnmount.current) {\n focusOnUnmount.current.focus();\n }\n };\n }, [ref]);\n\n let titleId = useId();\n let descriptionId = useSlotId();\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n\n return {\n toastProps: {\n role: 'alert',\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n 'aria-describedby': props['aria-describedby'] || descriptionId,\n 'aria-details': props['aria-details'],\n // Hide toasts that are animating out so VoiceOver doesn't announce them.\n 'aria-hidden': animation === 'exiting' ? 'true' : undefined\n },\n titleProps: {\n id: titleId\n },\n descriptionProps: {\n id: descriptionId\n },\n closeButtonProps: {\n 'aria-label': stringFormatter.format('close'),\n onPress: () => state.close(key)\n }\n };\n}\n"],"names":[],"version":3,"file":"useToast.module.js.map"}
1
+ {"mappings":";;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAkCM,SAAS,0CAAY,KAAwB,EAAE,KAAoB,EAAE,GAAuC;IACjH,IAAI,OACF,GAAG,SACH,KAAK,WACL,OAAO,aACP,SAAS,EACV,GAAG,MAAM,KAAK;IAEf,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,CAAC,OACH;QAGF,MAAM,KAAK,CAAC;QACZ,OAAO;YACL,MAAM,KAAK;QACb;IACF,GAAG;QAAC;QAAO;KAAQ;IAEnB,IAAI,CAAC,WAAW,aAAa,GAAG,CAAA,GAAA,YAAI,EAAE,QAAQ,CAAC;IAC/C,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,cAAc,cAAc,cAAc,UAC5C,aAAa;IAEjB,GAAG;QAAC;KAAU;IAEd,IAAI,UAAU,CAAA,GAAA,YAAI;IAClB,IAAI,gBAAgB,CAAA,GAAA,gBAAQ;IAC5B,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAEhE,OAAO;QACL,YAAY;YACV,MAAM;YACN,cAAc;YACd,cAAc,KAAK,CAAC,aAAa;YACjC,mBAAmB,KAAK,CAAC,kBAAkB,IAAI;YAC/C,oBAAoB,KAAK,CAAC,mBAAmB,IAAI;YACjD,gBAAgB,KAAK,CAAC,eAAe;YACrC,yEAAyE;YACzE,eAAe,cAAc,YAAY,SAAS;YAClD,UAAU;QACZ;QACA,cAAc;YACZ,MAAM;YACN,eAAe;YACf,OAAO;gBACL,YAAY,aAAa,cAAc,OAAO,YAAY;YAC5D;QACF;QACA,YAAY;YACV,IAAI;QACN;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,kBAAkB;YAChB,cAAc,gBAAgB,MAAM,CAAC;YACrC,SAAS,IAAM,MAAM,KAAK,CAAC;QAC7B;IACF;AACF","sources":["packages/@react-aria/toast/src/useToast.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 {AriaButtonProps} from '@react-types/button';\nimport {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport React, {useEffect} from 'react';\nimport {useId, useSlotId} from '@react-aria/utils';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastProps<T> extends AriaLabelingProps {\n /** The toast object. */\n toast: QueuedToast<T>\n}\n\nexport interface ToastAria {\n /** Props for the toast container, non-modal dialog element. */\n toastProps: DOMAttributes,\n /** Props for the toast content alert message. */\n contentProps: DOMAttributes,\n /** Props for the toast title element. */\n titleProps: DOMAttributes,\n /** Props for the toast description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the toast close button. */\n closeButtonProps: AriaButtonProps\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast component.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement | null>): ToastAria {\n let {\n key,\n timer,\n timeout,\n animation\n } = props.toast;\n\n useEffect(() => {\n if (!timer) {\n return;\n }\n\n timer.reset(timeout);\n return () => {\n timer.pause();\n };\n }, [timer, timeout]);\n\n let [isEntered, setIsEntered] = React.useState(false);\n useEffect(() => {\n if (animation === 'entering' || animation === 'queued') {\n setIsEntered(true);\n }\n }, [animation]);\n\n let titleId = useId();\n let descriptionId = useSlotId();\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n\n return {\n toastProps: {\n role: 'alertdialog',\n 'aria-modal': 'false',\n 'aria-label': props['aria-label'],\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n 'aria-describedby': props['aria-describedby'] || descriptionId,\n 'aria-details': props['aria-details'],\n // Hide toasts that are animating out so VoiceOver doesn't announce them.\n 'aria-hidden': animation === 'exiting' ? 'true' : undefined,\n tabIndex: 0\n },\n contentProps: {\n role: 'alert',\n 'aria-atomic': 'true',\n style: {\n visibility: isEntered || animation === null ? 'visible' : 'hidden'\n }\n },\n titleProps: {\n id: titleId\n },\n descriptionProps: {\n id: descriptionId\n },\n closeButtonProps: {\n 'aria-label': stringFormatter.format('close'),\n onPress: () => state.close(key)\n }\n };\n}\n"],"names":[],"version":3,"file":"useToast.module.js.map"}
@@ -25,12 +25,70 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
25
25
  let stringFormatter = (0, $eO7VF$reactariai18n.useLocalizedStringFormatter)((0, ($parcel$interopDefault($f49b2d6c91681304$exports))), '@react-aria/toast');
26
26
  let { landmarkProps: landmarkProps } = (0, $eO7VF$reactarialandmark.useLandmark)({
27
27
  role: 'region',
28
- 'aria-label': props['aria-label'] || stringFormatter.format('notifications')
28
+ 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {
29
+ count: state.visibleToasts.length
30
+ })
29
31
  }, ref);
30
32
  let { hoverProps: hoverProps } = (0, $eO7VF$reactariainteractions.useHover)({
31
33
  onHoverStart: state.pauseAll,
32
34
  onHoverEnd: state.resumeAll
33
35
  });
36
+ // Manage focus within the toast region.
37
+ // If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.
38
+ // We might be making an assumption with how this works if someone implements the priority queue differently, or
39
+ // if they only show one toast at a time.
40
+ let toasts = (0, $eO7VF$react.useRef)([]);
41
+ let prevVisibleToasts = (0, $eO7VF$react.useRef)(state.visibleToasts);
42
+ let focusedToast = (0, $eO7VF$react.useRef)(null);
43
+ (0, $eO7VF$reactariautils.useLayoutEffect)(()=>{
44
+ // If no toast has focus, then don't do anything.
45
+ if (focusedToast.current === -1 || state.visibleToasts.length === 0) {
46
+ toasts.current = [];
47
+ prevVisibleToasts.current = state.visibleToasts;
48
+ return;
49
+ }
50
+ toasts.current = [
51
+ ...ref.current.querySelectorAll('[role="alertdialog"]')
52
+ ];
53
+ // If the visible toasts haven't changed, we don't need to do anything.
54
+ if (prevVisibleToasts.current.length === state.visibleToasts.length && state.visibleToasts.every((t, i)=>t.key === prevVisibleToasts.current[i].key)) {
55
+ prevVisibleToasts.current = state.visibleToasts;
56
+ return;
57
+ }
58
+ // Get a list of all toasts by index and add info if they are removed.
59
+ let allToasts = prevVisibleToasts.current.map((t, i)=>({
60
+ ...t,
61
+ i: i,
62
+ isRemoved: !state.visibleToasts.some((t2)=>t.key === t2.key)
63
+ }));
64
+ let removedFocusedToastIndex = allToasts.findIndex((t)=>t.i === focusedToast.current);
65
+ // If the focused toast was removed, focus the next or previous toast.
66
+ if (removedFocusedToastIndex > -1) {
67
+ let i = 0;
68
+ let nextToast;
69
+ let prevToast;
70
+ while(i <= removedFocusedToastIndex){
71
+ if (!allToasts[i].isRemoved) prevToast = Math.max(0, i - 1);
72
+ i++;
73
+ }
74
+ while(i < allToasts.length){
75
+ if (!allToasts[i].isRemoved) {
76
+ nextToast = i - 1;
77
+ break;
78
+ }
79
+ i++;
80
+ }
81
+ // in the case where it's one toast at a time, both will be undefined, but we know the index must be 0
82
+ if (prevToast === undefined && nextToast === undefined) prevToast = 0;
83
+ // prioritize going to newer toasts
84
+ if (prevToast >= 0 && prevToast < toasts.current.length) (0, $eO7VF$reactariautils.focusWithoutScrolling)(toasts.current[prevToast]);
85
+ else if (nextToast >= 0 && nextToast < toasts.current.length) (0, $eO7VF$reactariautils.focusWithoutScrolling)(toasts.current[nextToast]);
86
+ }
87
+ prevVisibleToasts.current = state.visibleToasts;
88
+ }, [
89
+ state.visibleToasts,
90
+ ref
91
+ ]);
34
92
  let lastFocused = (0, $eO7VF$react.useRef)(null);
35
93
  let { focusWithinProps: focusWithinProps } = (0, $eO7VF$reactariainteractions.useFocusWithin)({
36
94
  onFocusWithin: (e)=>{
@@ -42,15 +100,27 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
42
100
  lastFocused.current = null;
43
101
  }
44
102
  });
45
- // When the region unmounts, restore focus to the last element that had focus
46
- // before the user moved focus into the region.
47
- // TODO: handle when the element has unmounted like FocusScope does?
48
- // eslint-disable-next-line arrow-body-style
103
+ // When the number of visible toasts becomes 0 or the region unmounts,
104
+ // restore focus to the last element that had focus before the user moved focus
105
+ // into the region. FocusScope restore focus doesn't update whenever the focus
106
+ // moves in, it only happens once, so we correct it.
107
+ // Because we're in a hook, we can't control if the user unmounts or not.
108
+ (0, $eO7VF$react.useEffect)(()=>{
109
+ if (state.visibleToasts.length === 0 && lastFocused.current && document.body.contains(lastFocused.current)) {
110
+ if ((0, $eO7VF$reactariainteractions.getInteractionModality)() === 'pointer') (0, $eO7VF$reactariautils.focusWithoutScrolling)(lastFocused.current);
111
+ else lastFocused.current.focus();
112
+ lastFocused.current = null;
113
+ }
114
+ }, [
115
+ ref,
116
+ state.visibleToasts.length
117
+ ]);
49
118
  (0, $eO7VF$react.useEffect)(()=>{
50
119
  return ()=>{
51
120
  if (lastFocused.current && document.body.contains(lastFocused.current)) {
52
121
  if ((0, $eO7VF$reactariainteractions.getInteractionModality)() === 'pointer') (0, $eO7VF$reactariautils.focusWithoutScrolling)(lastFocused.current);
53
122
  else lastFocused.current.focus();
123
+ lastFocused.current = null;
54
124
  }
55
125
  };
56
126
  }, [
@@ -64,7 +134,16 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
64
134
  // - allows focus even outside a containing focus scope
65
135
  // - doesn’t dismiss overlays when clicking on it, even though it is outside
66
136
  // @ts-ignore
67
- 'data-react-aria-top-layer': true
137
+ 'data-react-aria-top-layer': true,
138
+ // listen to focus events separate from focuswithin because that will only fire once
139
+ // and we need to follow all focus changes
140
+ onFocus: (e)=>{
141
+ let target = e.target.closest('[role="alertdialog"]');
142
+ focusedToast.current = toasts.current.findIndex((t)=>t === target);
143
+ },
144
+ onBlur: ()=>{
145
+ focusedToast.current = -1;
146
+ }
68
147
  })
69
148
  };
70
149
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BO,SAAS,0CAAkB,KAA2B,EAAE,KAAoB,EAAE,GAA2B;IAC9G,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,oCAAU,EAAE;QAChC,MAAM;QACN,cAAc,KAAK,CAAC,aAAa,IAAI,gBAAgB,MAAM,CAAC;IAC9D,GAAG;IAEH,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;QAC1B,cAAc,MAAM,QAAQ;QAC5B,YAAY,MAAM,SAAS;IAC7B;IAEA,IAAI,cAAc,CAAA,GAAA,mBAAK,EAAE;IACzB,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,2CAAa,EAAE;QACtC,eAAe,CAAC;YACd,MAAM,QAAQ;YACd,YAAY,OAAO,GAAG,EAAE,aAAa;QACvC;QACA,cAAc;YACZ,MAAM,SAAS;YACf,YAAY,OAAO,GAAG;QACxB;IACF;IAEA,6EAA6E;IAC7E,+CAA+C;IAC/C,oEAAoE;IACpE,4CAA4C;IAC5C,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,YAAY,OAAO,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,YAAY,OAAO;gBACnE,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,CAAA,GAAA,2CAAoB,EAAE,YAAY,OAAO;qBAEzC,YAAY,OAAO,CAAC,KAAK;;QAG/B;IACF,GAAG;QAAC;KAAI;IAER,OAAO;QACL,aAAa,CAAA,GAAA,gCAAS,EAAE,eAAe,YAAY,kBAAkB;YACnE,UAAU;YACV,sDAAsD;YACtD,iDAAiD;YACjD,yDAAyD;YACzD,8EAA8E;YAC9E,aAAa;YACb,6BAA6B;QAC/B;IACF;AACF","sources":["packages/@react-aria/toast/src/useToastRegion.ts"],"sourcesContent":["import {AriaLabelingProps, DOMAttributes} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {ToastState} from '@react-stately/toast';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications')\n }, ref);\n\n let {hoverProps} = useHover({\n onHoverStart: state.pauseAll,\n onHoverEnd: state.resumeAll\n });\n\n let lastFocused = useRef(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n state.pauseAll();\n lastFocused.current = e.relatedTarget;\n },\n onBlurWithin: () => {\n state.resumeAll();\n lastFocused.current = null;\n }\n });\n\n // When the region unmounts, restore focus to the last element that had focus\n // before the user moved focus into the region.\n // TODO: handle when the element has unmounted like FocusScope does?\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n if (lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n }\n };\n }, [ref]);\n\n return {\n regionProps: mergeProps(landmarkProps, hoverProps, focusWithinProps, {\n tabIndex: -1,\n // Mark the toast region as a \"top layer\", so that it:\n // - is not aria-hidden when opening an overlay\n // - allows focus even outside a containing focus scope\n // - doesn’t dismiss overlays when clicking on it, even though it is outside\n // @ts-ignore\n 'data-react-aria-top-layer': true\n })\n };\n}\n"],"names":[],"version":3,"file":"useToastRegion.main.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BO,SAAS,0CAAkB,KAA2B,EAAE,KAAoB,EAAE,GAAkC;IACrH,IAAI,kBAAkB,CAAA,GAAA,gDAA0B,EAAE,CAAA,GAAA,mDAAW,GAAG;IAChE,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,oCAAU,EAAE;QAChC,MAAM;QACN,cAAc,KAAK,CAAC,aAAa,IAAI,gBAAgB,MAAM,CAAC,iBAAiB;YAAC,OAAO,MAAM,aAAa,CAAC,MAAM;QAAA;IACjH,GAAG;IAEH,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAA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AG;QAAC;QAAK,MAAM,aAAa,CAAC,MAAM;KAAC;IAEpC,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;YACL,IAAI,YAAY,OAAO,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,YAAY,OAAO,GAAG;gBACtE,IAAI,CAAA,GAAA,mDAAqB,QAAQ,WAC/B,CAAA,GAAA,2CAAoB,EAAE,YAAY,OAAO;qBAEzC,YAAY,OAAO,CAAC,KAAK;gBAE3B,YAAY,OAAO,GAAG;YACxB;QACF;IACF,GAAG;QAAC;KAAI;IAER,OAAO;QACL,aAAa,CAAA,GAAA,gCAAS,EAAE,eAAe,YAAY,kBAAkB;YACnE,UAAU;YACV,sDAAsD;YACtD,iDAAiD;YACjD,yDAAyD;YACzD,8EAA8E;YAC9E,aAAa;YACb,6BAA6B;YAC7B,oFAAoF;YACpF,0CAA0C;YAC1C,SAAS,CAAC;gBACR,IAAI,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC;gBAC9B,aAAa,OAAO,GAAG,OAAO,OAAO,CAAC,SAAS,CAAC,CAAA,IAAK,MAAM;YAC7D;YACA,QAAQ;gBACN,aAAa,OAAO,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/@react-aria/toast/src/useToastRegion.ts"],"sourcesContent":["import {AriaLabelingProps, DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useLayoutEffect} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ToastState} from '@react-stately/toast';\nimport {useEffect, useRef} from 'react';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement | null>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {count: state.visibleToasts.length})\n }, ref);\n\n let {hoverProps} = useHover({\n onHoverStart: state.pauseAll,\n onHoverEnd: state.resumeAll\n });\n\n // Manage focus within the toast region.\n // If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.\n // We might be making an assumption with how this works if someone implements the priority queue differently, or\n // if they only show one toast at a time.\n let toasts = useRef([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')];\n // If the visible toasts haven't changed, we don't need to do anything.\n if (prevVisibleToasts.current.length === state.visibleToasts.length\n && state.visibleToasts.every((t, i) => t.key === prevVisibleToasts.current[i].key)) {\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n // Get a list of all toasts by index and add info if they are removed.\n let allToasts = prevVisibleToasts.current\n .map((t, i) => ({\n ...t,\n i,\n isRemoved: !state.visibleToasts.some(t2 => t.key === t2.key)\n }));\n\n let removedFocusedToastIndex = allToasts.findIndex(t => t.i === focusedToast.current);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n let i = 0;\n let nextToast;\n let prevToast;\n while (i <= removedFocusedToastIndex) {\n if (!allToasts[i].isRemoved) {\n prevToast = Math.max(0, i - 1);\n }\n i++;\n }\n while (i < allToasts.length) {\n if (!allToasts[i].isRemoved) {\n nextToast = i - 1;\n break;\n }\n i++;\n }\n\n // in the case where it's one toast at a time, both will be undefined, but we know the index must be 0\n if (prevToast === undefined && nextToast === undefined) {\n prevToast = 0;\n }\n\n // prioritize going to newer toasts\n if (prevToast >= 0 && prevToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[prevToast]);\n } else if (nextToast >= 0 && nextToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[nextToast]);\n }\n }\n\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref]);\n\n let lastFocused = useRef(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n state.pauseAll();\n lastFocused.current = e.relatedTarget;\n },\n onBlurWithin: () => {\n state.resumeAll();\n lastFocused.current = null;\n }\n });\n\n // When the number of visible toasts becomes 0 or the region unmounts,\n // restore focus to the last element that had focus before the user moved focus\n // into the region. FocusScope restore focus doesn't update whenever the focus\n // moves in, it only happens once, so we correct it.\n // Because we're in a hook, we can't control if the user unmounts or not.\n useEffect(() => {\n if (state.visibleToasts.length === 0 && lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n }, [ref, state.visibleToasts.length]);\n\n useEffect(() => {\n return () => {\n if (lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n };\n }, [ref]);\n\n return {\n regionProps: mergeProps(landmarkProps, hoverProps, focusWithinProps, {\n tabIndex: -1,\n // Mark the toast region as a \"top layer\", so that it:\n // - is not aria-hidden when opening an overlay\n // - allows focus even outside a containing focus scope\n // - doesn’t dismiss overlays when clicking on it, even though it is outside\n // @ts-ignore\n 'data-react-aria-top-layer': true,\n // listen to focus events separate from focuswithin because that will only fire once\n // and we need to follow all focus changes\n onFocus: (e) => {\n let target = e.target.closest('[role=\"alertdialog\"]');\n focusedToast.current = toasts.current.findIndex(t => t === target);\n },\n onBlur: () => {\n focusedToast.current = -1;\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useToastRegion.main.js.map"}
@@ -1,5 +1,5 @@
1
1
  import $ckyCP$intlStringsmodulejs from "./intlStrings.mjs";
2
- import {focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
2
+ import {useLayoutEffect as $ckyCP$useLayoutEffect, focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
3
3
  import {useHover as $ckyCP$useHover, useFocusWithin as $ckyCP$useFocusWithin, getInteractionModality as $ckyCP$getInteractionModality} from "@react-aria/interactions";
4
4
  import {useRef as $ckyCP$useRef, useEffect as $ckyCP$useEffect} from "react";
5
5
  import {useLandmark as $ckyCP$useLandmark} from "@react-aria/landmark";
@@ -19,12 +19,70 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
19
19
  let stringFormatter = (0, $ckyCP$useLocalizedStringFormatter)((0, ($parcel$interopDefault($ckyCP$intlStringsmodulejs))), '@react-aria/toast');
20
20
  let { landmarkProps: landmarkProps } = (0, $ckyCP$useLandmark)({
21
21
  role: 'region',
22
- 'aria-label': props['aria-label'] || stringFormatter.format('notifications')
22
+ 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {
23
+ count: state.visibleToasts.length
24
+ })
23
25
  }, ref);
24
26
  let { hoverProps: hoverProps } = (0, $ckyCP$useHover)({
25
27
  onHoverStart: state.pauseAll,
26
28
  onHoverEnd: state.resumeAll
27
29
  });
30
+ // Manage focus within the toast region.
31
+ // If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.
32
+ // We might be making an assumption with how this works if someone implements the priority queue differently, or
33
+ // if they only show one toast at a time.
34
+ let toasts = (0, $ckyCP$useRef)([]);
35
+ let prevVisibleToasts = (0, $ckyCP$useRef)(state.visibleToasts);
36
+ let focusedToast = (0, $ckyCP$useRef)(null);
37
+ (0, $ckyCP$useLayoutEffect)(()=>{
38
+ // If no toast has focus, then don't do anything.
39
+ if (focusedToast.current === -1 || state.visibleToasts.length === 0) {
40
+ toasts.current = [];
41
+ prevVisibleToasts.current = state.visibleToasts;
42
+ return;
43
+ }
44
+ toasts.current = [
45
+ ...ref.current.querySelectorAll('[role="alertdialog"]')
46
+ ];
47
+ // If the visible toasts haven't changed, we don't need to do anything.
48
+ if (prevVisibleToasts.current.length === state.visibleToasts.length && state.visibleToasts.every((t, i)=>t.key === prevVisibleToasts.current[i].key)) {
49
+ prevVisibleToasts.current = state.visibleToasts;
50
+ return;
51
+ }
52
+ // Get a list of all toasts by index and add info if they are removed.
53
+ let allToasts = prevVisibleToasts.current.map((t, i)=>({
54
+ ...t,
55
+ i: i,
56
+ isRemoved: !state.visibleToasts.some((t2)=>t.key === t2.key)
57
+ }));
58
+ let removedFocusedToastIndex = allToasts.findIndex((t)=>t.i === focusedToast.current);
59
+ // If the focused toast was removed, focus the next or previous toast.
60
+ if (removedFocusedToastIndex > -1) {
61
+ let i = 0;
62
+ let nextToast;
63
+ let prevToast;
64
+ while(i <= removedFocusedToastIndex){
65
+ if (!allToasts[i].isRemoved) prevToast = Math.max(0, i - 1);
66
+ i++;
67
+ }
68
+ while(i < allToasts.length){
69
+ if (!allToasts[i].isRemoved) {
70
+ nextToast = i - 1;
71
+ break;
72
+ }
73
+ i++;
74
+ }
75
+ // in the case where it's one toast at a time, both will be undefined, but we know the index must be 0
76
+ if (prevToast === undefined && nextToast === undefined) prevToast = 0;
77
+ // prioritize going to newer toasts
78
+ if (prevToast >= 0 && prevToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[prevToast]);
79
+ else if (nextToast >= 0 && nextToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[nextToast]);
80
+ }
81
+ prevVisibleToasts.current = state.visibleToasts;
82
+ }, [
83
+ state.visibleToasts,
84
+ ref
85
+ ]);
28
86
  let lastFocused = (0, $ckyCP$useRef)(null);
29
87
  let { focusWithinProps: focusWithinProps } = (0, $ckyCP$useFocusWithin)({
30
88
  onFocusWithin: (e)=>{
@@ -36,15 +94,27 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
36
94
  lastFocused.current = null;
37
95
  }
38
96
  });
39
- // When the region unmounts, restore focus to the last element that had focus
40
- // before the user moved focus into the region.
41
- // TODO: handle when the element has unmounted like FocusScope does?
42
- // eslint-disable-next-line arrow-body-style
97
+ // When the number of visible toasts becomes 0 or the region unmounts,
98
+ // restore focus to the last element that had focus before the user moved focus
99
+ // into the region. FocusScope restore focus doesn't update whenever the focus
100
+ // moves in, it only happens once, so we correct it.
101
+ // Because we're in a hook, we can't control if the user unmounts or not.
102
+ (0, $ckyCP$useEffect)(()=>{
103
+ if (state.visibleToasts.length === 0 && lastFocused.current && document.body.contains(lastFocused.current)) {
104
+ if ((0, $ckyCP$getInteractionModality)() === 'pointer') (0, $ckyCP$focusWithoutScrolling)(lastFocused.current);
105
+ else lastFocused.current.focus();
106
+ lastFocused.current = null;
107
+ }
108
+ }, [
109
+ ref,
110
+ state.visibleToasts.length
111
+ ]);
43
112
  (0, $ckyCP$useEffect)(()=>{
44
113
  return ()=>{
45
114
  if (lastFocused.current && document.body.contains(lastFocused.current)) {
46
115
  if ((0, $ckyCP$getInteractionModality)() === 'pointer') (0, $ckyCP$focusWithoutScrolling)(lastFocused.current);
47
116
  else lastFocused.current.focus();
117
+ lastFocused.current = null;
48
118
  }
49
119
  };
50
120
  }, [
@@ -58,7 +128,16 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
58
128
  // - allows focus even outside a containing focus scope
59
129
  // - doesn’t dismiss overlays when clicking on it, even though it is outside
60
130
  // @ts-ignore
61
- 'data-react-aria-top-layer': true
131
+ 'data-react-aria-top-layer': true,
132
+ // listen to focus events separate from focuswithin because that will only fire once
133
+ // and we need to follow all focus changes
134
+ onFocus: (e)=>{
135
+ let target = e.target.closest('[role="alertdialog"]');
136
+ focusedToast.current = toasts.current.findIndex((t)=>t === target);
137
+ },
138
+ onBlur: ()=>{
139
+ focusedToast.current = -1;
140
+ }
62
141
  })
63
142
  };
64
143
  }
@@ -1,5 +1,5 @@
1
1
  import $ckyCP$intlStringsmodulejs from "./intlStrings.module.js";
2
- import {focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
2
+ import {useLayoutEffect as $ckyCP$useLayoutEffect, focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
3
3
  import {useHover as $ckyCP$useHover, useFocusWithin as $ckyCP$useFocusWithin, getInteractionModality as $ckyCP$getInteractionModality} from "@react-aria/interactions";
4
4
  import {useRef as $ckyCP$useRef, useEffect as $ckyCP$useEffect} from "react";
5
5
  import {useLandmark as $ckyCP$useLandmark} from "@react-aria/landmark";
@@ -19,12 +19,70 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
19
19
  let stringFormatter = (0, $ckyCP$useLocalizedStringFormatter)((0, ($parcel$interopDefault($ckyCP$intlStringsmodulejs))), '@react-aria/toast');
20
20
  let { landmarkProps: landmarkProps } = (0, $ckyCP$useLandmark)({
21
21
  role: 'region',
22
- 'aria-label': props['aria-label'] || stringFormatter.format('notifications')
22
+ 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {
23
+ count: state.visibleToasts.length
24
+ })
23
25
  }, ref);
24
26
  let { hoverProps: hoverProps } = (0, $ckyCP$useHover)({
25
27
  onHoverStart: state.pauseAll,
26
28
  onHoverEnd: state.resumeAll
27
29
  });
30
+ // Manage focus within the toast region.
31
+ // If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.
32
+ // We might be making an assumption with how this works if someone implements the priority queue differently, or
33
+ // if they only show one toast at a time.
34
+ let toasts = (0, $ckyCP$useRef)([]);
35
+ let prevVisibleToasts = (0, $ckyCP$useRef)(state.visibleToasts);
36
+ let focusedToast = (0, $ckyCP$useRef)(null);
37
+ (0, $ckyCP$useLayoutEffect)(()=>{
38
+ // If no toast has focus, then don't do anything.
39
+ if (focusedToast.current === -1 || state.visibleToasts.length === 0) {
40
+ toasts.current = [];
41
+ prevVisibleToasts.current = state.visibleToasts;
42
+ return;
43
+ }
44
+ toasts.current = [
45
+ ...ref.current.querySelectorAll('[role="alertdialog"]')
46
+ ];
47
+ // If the visible toasts haven't changed, we don't need to do anything.
48
+ if (prevVisibleToasts.current.length === state.visibleToasts.length && state.visibleToasts.every((t, i)=>t.key === prevVisibleToasts.current[i].key)) {
49
+ prevVisibleToasts.current = state.visibleToasts;
50
+ return;
51
+ }
52
+ // Get a list of all toasts by index and add info if they are removed.
53
+ let allToasts = prevVisibleToasts.current.map((t, i)=>({
54
+ ...t,
55
+ i: i,
56
+ isRemoved: !state.visibleToasts.some((t2)=>t.key === t2.key)
57
+ }));
58
+ let removedFocusedToastIndex = allToasts.findIndex((t)=>t.i === focusedToast.current);
59
+ // If the focused toast was removed, focus the next or previous toast.
60
+ if (removedFocusedToastIndex > -1) {
61
+ let i = 0;
62
+ let nextToast;
63
+ let prevToast;
64
+ while(i <= removedFocusedToastIndex){
65
+ if (!allToasts[i].isRemoved) prevToast = Math.max(0, i - 1);
66
+ i++;
67
+ }
68
+ while(i < allToasts.length){
69
+ if (!allToasts[i].isRemoved) {
70
+ nextToast = i - 1;
71
+ break;
72
+ }
73
+ i++;
74
+ }
75
+ // in the case where it's one toast at a time, both will be undefined, but we know the index must be 0
76
+ if (prevToast === undefined && nextToast === undefined) prevToast = 0;
77
+ // prioritize going to newer toasts
78
+ if (prevToast >= 0 && prevToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[prevToast]);
79
+ else if (nextToast >= 0 && nextToast < toasts.current.length) (0, $ckyCP$focusWithoutScrolling)(toasts.current[nextToast]);
80
+ }
81
+ prevVisibleToasts.current = state.visibleToasts;
82
+ }, [
83
+ state.visibleToasts,
84
+ ref
85
+ ]);
28
86
  let lastFocused = (0, $ckyCP$useRef)(null);
29
87
  let { focusWithinProps: focusWithinProps } = (0, $ckyCP$useFocusWithin)({
30
88
  onFocusWithin: (e)=>{
@@ -36,15 +94,27 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
36
94
  lastFocused.current = null;
37
95
  }
38
96
  });
39
- // When the region unmounts, restore focus to the last element that had focus
40
- // before the user moved focus into the region.
41
- // TODO: handle when the element has unmounted like FocusScope does?
42
- // eslint-disable-next-line arrow-body-style
97
+ // When the number of visible toasts becomes 0 or the region unmounts,
98
+ // restore focus to the last element that had focus before the user moved focus
99
+ // into the region. FocusScope restore focus doesn't update whenever the focus
100
+ // moves in, it only happens once, so we correct it.
101
+ // Because we're in a hook, we can't control if the user unmounts or not.
102
+ (0, $ckyCP$useEffect)(()=>{
103
+ if (state.visibleToasts.length === 0 && lastFocused.current && document.body.contains(lastFocused.current)) {
104
+ if ((0, $ckyCP$getInteractionModality)() === 'pointer') (0, $ckyCP$focusWithoutScrolling)(lastFocused.current);
105
+ else lastFocused.current.focus();
106
+ lastFocused.current = null;
107
+ }
108
+ }, [
109
+ ref,
110
+ state.visibleToasts.length
111
+ ]);
43
112
  (0, $ckyCP$useEffect)(()=>{
44
113
  return ()=>{
45
114
  if (lastFocused.current && document.body.contains(lastFocused.current)) {
46
115
  if ((0, $ckyCP$getInteractionModality)() === 'pointer') (0, $ckyCP$focusWithoutScrolling)(lastFocused.current);
47
116
  else lastFocused.current.focus();
117
+ lastFocused.current = null;
48
118
  }
49
119
  };
50
120
  }, [
@@ -58,7 +128,16 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
58
128
  // - allows focus even outside a containing focus scope
59
129
  // - doesn’t dismiss overlays when clicking on it, even though it is outside
60
130
  // @ts-ignore
61
- 'data-react-aria-top-layer': true
131
+ 'data-react-aria-top-layer': true,
132
+ // listen to focus events separate from focuswithin because that will only fire once
133
+ // and we need to follow all focus changes
134
+ onFocus: (e)=>{
135
+ let target = e.target.closest('[role="alertdialog"]');
136
+ focusedToast.current = toasts.current.findIndex((t)=>t === target);
137
+ },
138
+ onBlur: ()=>{
139
+ focusedToast.current = -1;
140
+ }
62
141
  })
63
142
  };
64
143
  }
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;AA2BO,SAAS,0CAAkB,KAA2B,EAAE,KAAoB,EAAE,GAA2B;IAC9G,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,kBAAU,EAAE;QAChC,MAAM;QACN,cAAc,KAAK,CAAC,aAAa,IAAI,gBAAgB,MAAM,CAAC;IAC9D,GAAG;IAEH,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC1B,cAAc,MAAM,QAAQ;QAC5B,YAAY,MAAM,SAAS;IAC7B;IAEA,IAAI,cAAc,CAAA,GAAA,aAAK,EAAE;IACzB,IAAI,oBAAC,gBAAgB,EAAC,GAAG,CAAA,GAAA,qBAAa,EAAE;QACtC,eAAe,CAAC;YACd,MAAM,QAAQ;YACd,YAAY,OAAO,GAAG,EAAE,aAAa;QACvC;QACA,cAAc;YACZ,MAAM,SAAS;YACf,YAAY,OAAO,GAAG;QACxB;IACF;IAEA,6EAA6E;IAC7E,+CAA+C;IAC/C,oEAAoE;IACpE,4CAA4C;IAC5C,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO;YACL,IAAI,YAAY,OAAO,IAAI,SAAS,IAAI,CAAC,QAAQ,CAAC,YAAY,OAAO;gBACnE,IAAI,CAAA,GAAA,6BAAqB,QAAQ,WAC/B,CAAA,GAAA,4BAAoB,EAAE,YAAY,OAAO;qBAEzC,YAAY,OAAO,CAAC,KAAK;;QAG/B;IACF,GAAG;QAAC;KAAI;IAER,OAAO;QACL,aAAa,CAAA,GAAA,iBAAS,EAAE,eAAe,YAAY,kBAAkB;YACnE,UAAU;YACV,sDAAsD;YACtD,iDAAiD;YACjD,yDAAyD;YACzD,8EAA8E;YAC9E,aAAa;YACb,6BAA6B;QAC/B;IACF;AACF","sources":["packages/@react-aria/toast/src/useToastRegion.ts"],"sourcesContent":["import {AriaLabelingProps, DOMAttributes} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {RefObject, useEffect, useRef} from 'react';\nimport {ToastState} from '@react-stately/toast';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications')\n }, ref);\n\n let {hoverProps} = useHover({\n onHoverStart: state.pauseAll,\n onHoverEnd: state.resumeAll\n });\n\n let lastFocused = useRef(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n state.pauseAll();\n lastFocused.current = e.relatedTarget;\n },\n onBlurWithin: () => {\n state.resumeAll();\n lastFocused.current = null;\n }\n });\n\n // When the region unmounts, restore focus to the last element that had focus\n // before the user moved focus into the region.\n // TODO: handle when the element has unmounted like FocusScope does?\n // eslint-disable-next-line arrow-body-style\n useEffect(() => {\n return () => {\n if (lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n }\n };\n }, [ref]);\n\n return {\n regionProps: mergeProps(landmarkProps, hoverProps, focusWithinProps, {\n tabIndex: -1,\n // Mark the toast region as a \"top layer\", so that it:\n // - is not aria-hidden when opening an overlay\n // - allows focus even outside a containing focus scope\n // - doesn’t dismiss overlays when clicking on it, even though it is outside\n // @ts-ignore\n 'data-react-aria-top-layer': true\n })\n };\n}\n"],"names":[],"version":3,"file":"useToastRegion.module.js.map"}
1
+ {"mappings":";;;;;;;;;;;;;;;;;AA2BO,SAAS,0CAAkB,KAA2B,EAAE,KAAoB,EAAE,GAAkC;IACrH,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,iBAAC,aAAa,EAAC,GAAG,CAAA,GAAA,kBAAU,EAAE;QAChC,MAAM;QACN,cAAc,KAAK,CAAC,aAAa,IAAI,gBAAgB,MAAM,CAAC,iBAAiB;YAAC,OAAO,MAAM,aAAa,CAAC,MAAM;QAAA;IACjH,GAAG;IAEH,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO,EAAE;QAC1B,cAAc,MAAM,QAAQ;QAC5B,YAAY,MAAM,SAAS;IAC7B;IAEA,wCAAwC;IACxC,2HAA2H;IAC3H,gHAAgH;IAChH,yCAAyC;IACzC,IAAI,SAAS,CAAA,GAAA,aAAK,EAAE,EAAE;IACtB,IAAI,oBAAoB,CAAA,GAAA,aAAK,EAAE,MAAM,aAAa;IAClD,IAAI,eAAe,CAAA,GAAA,aAAK,EAAE;IAC1B,CAAA,GAAA,sBAAc,EAAE;QACd,iDAAiD;QACjD,IAAI,aAAa,OAAO,KAAK,MAAM,MAAM,aAAa,CAAC,MAAM,KAAK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AAe,YAAY,kBAAkB;YACnE,UAAU;YACV,sDAAsD;YACtD,iDAAiD;YACjD,yDAAyD;YACzD,8EAA8E;YAC9E,aAAa;YACb,6BAA6B;YAC7B,oFAAoF;YACpF,0CAA0C;YAC1C,SAAS,CAAC;gBACR,IAAI,SAAS,EAAE,MAAM,CAAC,OAAO,CAAC;gBAC9B,aAAa,OAAO,GAAG,OAAO,OAAO,CAAC,SAAS,CAAC,CAAA,IAAK,MAAM;YAC7D;YACA,QAAQ;gBACN,aAAa,OAAO,GAAG;YACzB;QACF;IACF;AACF","sources":["packages/@react-aria/toast/src/useToastRegion.ts"],"sourcesContent":["import {AriaLabelingProps, DOMAttributes, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, mergeProps, useLayoutEffect} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ToastState} from '@react-stately/toast';\nimport {useEffect, useRef} from 'react';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement | null>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {count: state.visibleToasts.length})\n }, ref);\n\n let {hoverProps} = useHover({\n onHoverStart: state.pauseAll,\n onHoverEnd: state.resumeAll\n });\n\n // Manage focus within the toast region.\n // If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.\n // We might be making an assumption with how this works if someone implements the priority queue differently, or\n // if they only show one toast at a time.\n let toasts = useRef([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')];\n // If the visible toasts haven't changed, we don't need to do anything.\n if (prevVisibleToasts.current.length === state.visibleToasts.length\n && state.visibleToasts.every((t, i) => t.key === prevVisibleToasts.current[i].key)) {\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n // Get a list of all toasts by index and add info if they are removed.\n let allToasts = prevVisibleToasts.current\n .map((t, i) => ({\n ...t,\n i,\n isRemoved: !state.visibleToasts.some(t2 => t.key === t2.key)\n }));\n\n let removedFocusedToastIndex = allToasts.findIndex(t => t.i === focusedToast.current);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n let i = 0;\n let nextToast;\n let prevToast;\n while (i <= removedFocusedToastIndex) {\n if (!allToasts[i].isRemoved) {\n prevToast = Math.max(0, i - 1);\n }\n i++;\n }\n while (i < allToasts.length) {\n if (!allToasts[i].isRemoved) {\n nextToast = i - 1;\n break;\n }\n i++;\n }\n\n // in the case where it's one toast at a time, both will be undefined, but we know the index must be 0\n if (prevToast === undefined && nextToast === undefined) {\n prevToast = 0;\n }\n\n // prioritize going to newer toasts\n if (prevToast >= 0 && prevToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[prevToast]);\n } else if (nextToast >= 0 && nextToast < toasts.current.length) {\n focusWithoutScrolling(toasts.current[nextToast]);\n }\n }\n\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref]);\n\n let lastFocused = useRef(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n state.pauseAll();\n lastFocused.current = e.relatedTarget;\n },\n onBlurWithin: () => {\n state.resumeAll();\n lastFocused.current = null;\n }\n });\n\n // When the number of visible toasts becomes 0 or the region unmounts,\n // restore focus to the last element that had focus before the user moved focus\n // into the region. FocusScope restore focus doesn't update whenever the focus\n // moves in, it only happens once, so we correct it.\n // Because we're in a hook, we can't control if the user unmounts or not.\n useEffect(() => {\n if (state.visibleToasts.length === 0 && lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n }, [ref, state.visibleToasts.length]);\n\n useEffect(() => {\n return () => {\n if (lastFocused.current && document.body.contains(lastFocused.current)) {\n if (getInteractionModality() === 'pointer') {\n focusWithoutScrolling(lastFocused.current);\n } else {\n lastFocused.current.focus();\n }\n lastFocused.current = null;\n }\n };\n }, [ref]);\n\n return {\n regionProps: mergeProps(landmarkProps, hoverProps, focusWithinProps, {\n tabIndex: -1,\n // Mark the toast region as a \"top layer\", so that it:\n // - is not aria-hidden when opening an overlay\n // - allows focus even outside a containing focus scope\n // - doesn’t dismiss overlays when clicking on it, even though it is outside\n // @ts-ignore\n 'data-react-aria-top-layer': true,\n // listen to focus events separate from focuswithin because that will only fire once\n // and we need to follow all focus changes\n onFocus: (e) => {\n let target = e.target.closest('[role=\"alertdialog\"]');\n focusedToast.current = toasts.current.findIndex(t => t === target);\n },\n onBlur: () => {\n focusedToast.current = -1;\n }\n })\n };\n}\n"],"names":[],"version":3,"file":"useToastRegion.module.js.map"}
@@ -1,6 +1,9 @@
1
1
  module.exports = {
2
2
  "close": `\u{5173}\u{95ED}`,
3
- "notifications": `\u{901A}\u{77E5}`
3
+ "notifications": (args, formatter)=>`${formatter.plural(args.count, {
4
+ one: ()=>`${formatter.number(args.count)} \u{4E2A}\u{901A}\u{77E5}`,
5
+ other: ()=>`${formatter.number(args.count)} \u{4E2A}\u{901A}\u{77E5}`
6
+ })}\u{3002}`
4
7
  };
5
8
 
6
9
 
@@ -1 +1 @@
1
- {"mappings":"AAAA,iBAAiB;IAAG,SAAS,CAAC,gBAAE,CAAC;IAC/B,iBAAiB,CAAC,gBAAE,CAAC;AACvB","sources":["packages/@react-aria/toast/intl/zh-CN.json"],"sourcesContent":["{\n \"close\": \"关闭\",\n \"notifications\": \"通知\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
1
+ {"mappings":"AAAA,iBAAiB;IAAG,SAAS,CAAC,gBAAE,CAAC;IAC/B,iBAAiB,CAAC,MAAM,YAAc,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE;YAAC,KAAK,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yBAAI,CAAC;YAAE,OAAO,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yBAAI,CAAC;QAAA,GAAG,QAAC,CAAC;AAClL","sources":["packages/@react-aria/toast/intl/zh-CN.json"],"sourcesContent":["{\n \"close\": \"关闭\",\n \"notifications\": \"{count, plural, one {# 个通知} other {# 个通知}}。\"\n}\n"],"names":[],"version":3,"file":"zh-CN.main.js.map"}
package/dist/zh-CN.mjs CHANGED
@@ -1,7 +1,10 @@
1
1
  var $122525af1cb737c7$exports = {};
2
2
  $122525af1cb737c7$exports = {
3
3
  "close": `\u{5173}\u{95ED}`,
4
- "notifications": `\u{901A}\u{77E5}`
4
+ "notifications": (args, formatter)=>`${formatter.plural(args.count, {
5
+ one: ()=>`${formatter.number(args.count)} \u{4E2A}\u{901A}\u{77E5}`,
6
+ other: ()=>`${formatter.number(args.count)} \u{4E2A}\u{901A}\u{77E5}`
7
+ })}\u{3002}`
5
8
  };
6
9
 
7
10
 
@@ -1,7 +1,10 @@
1
1
  var $122525af1cb737c7$exports = {};
2
2
  $122525af1cb737c7$exports = {
3
3
  "close": `\u{5173}\u{95ED}`,
4
- "notifications": `\u{901A}\u{77E5}`
4
+ "notifications": (args, formatter)=>`${formatter.plural(args.count, {
5
+ one: ()=>`${formatter.number(args.count)} \u{4E2A}\u{901A}\u{77E5}`,
6
+ other: ()=>`${formatter.number(args.count)} \u{4E2A}\u{901A}\u{77E5}`
7
+ })}\u{3002}`
5
8
  };
6
9
 
7
10
 
@@ -1 +1 @@
1
- {"mappings":";AAAA,4BAAiB;IAAG,SAAS,CAAC,gBAAE,CAAC;IAC/B,iBAAiB,CAAC,gBAAE,CAAC;AACvB","sources":["packages/@react-aria/toast/intl/zh-CN.json"],"sourcesContent":["{\n \"close\": \"关闭\",\n \"notifications\": \"通知\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
1
+ {"mappings":";AAAA,4BAAiB;IAAG,SAAS,CAAC,gBAAE,CAAC;IAC/B,iBAAiB,CAAC,MAAM,YAAc,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE;YAAC,KAAK,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yBAAI,CAAC;YAAE,OAAO,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yBAAI,CAAC;QAAA,GAAG,QAAC,CAAC;AAClL","sources":["packages/@react-aria/toast/intl/zh-CN.json"],"sourcesContent":["{\n \"close\": \"关闭\",\n \"notifications\": \"{count, plural, one {# 个通知} other {# 个通知}}。\"\n}\n"],"names":[],"version":3,"file":"zh-CN.module.js.map"}
@@ -1,6 +1,9 @@
1
1
  module.exports = {
2
2
  "close": `\u{95DC}\u{9589}`,
3
- "notifications": `\u{901A}\u{77E5}`
3
+ "notifications": (args, formatter)=>`${formatter.plural(args.count, {
4
+ one: ()=>`${formatter.number(args.count)} \u{500B}\u{901A}\u{77E5}`,
5
+ other: ()=>`${formatter.number(args.count)} \u{500B}\u{901A}\u{77E5}`
6
+ })}\u{3002}`
4
7
  };
5
8
 
6
9
 
@@ -1 +1 @@
1
- {"mappings":"AAAA,iBAAiB;IAAG,SAAS,CAAC,gBAAE,CAAC;IAC/B,iBAAiB,CAAC,gBAAE,CAAC;AACvB","sources":["packages/@react-aria/toast/intl/zh-TW.json"],"sourcesContent":["{\n \"close\": \"關閉\",\n \"notifications\": \"通知\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
1
+ {"mappings":"AAAA,iBAAiB;IAAG,SAAS,CAAC,gBAAE,CAAC;IAC/B,iBAAiB,CAAC,MAAM,YAAc,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE;YAAC,KAAK,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yBAAI,CAAC;YAAE,OAAO,IAAM,CAAC,EAAE,UAAU,MAAM,CAAC,KAAK,KAAK,EAAE,yBAAI,CAAC;QAAA,GAAG,QAAC,CAAC;AAClL","sources":["packages/@react-aria/toast/intl/zh-TW.json"],"sourcesContent":["{\n \"close\": \"關閉\",\n \"notifications\": \"{count, plural, one {# 個通知} other {# 個通知}}。\"\n}\n"],"names":[],"version":3,"file":"zh-TW.main.js.map"}
package/dist/zh-TW.mjs CHANGED
@@ -1,7 +1,10 @@
1
1
  var $52e8b1b00094e5a3$exports = {};
2
2
  $52e8b1b00094e5a3$exports = {
3
3
  "close": `\u{95DC}\u{9589}`,
4
- "notifications": `\u{901A}\u{77E5}`
4
+ "notifications": (args, formatter)=>`${formatter.plural(args.count, {
5
+ one: ()=>`${formatter.number(args.count)} \u{500B}\u{901A}\u{77E5}`,
6
+ other: ()=>`${formatter.number(args.count)} \u{500B}\u{901A}\u{77E5}`
7
+ })}\u{3002}`
5
8
  };
6
9
 
7
10