@fluentui/react-toast 9.0.6 → 9.1.0

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 (27) hide show
  1. package/CHANGELOG.json +58 -1
  2. package/CHANGELOG.md +18 -2
  3. package/lib/components/ToastContainer/useToastContainer.js +28 -11
  4. package/lib/components/ToastContainer/useToastContainer.js.map +1 -1
  5. package/lib/components/ToastContainer/useToastContainerStyles.styles.js +2 -2
  6. package/lib/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -1
  7. package/lib/components/Toaster/useToastAnnounce.js +47 -0
  8. package/lib/components/Toaster/useToastAnnounce.js.map +1 -0
  9. package/lib/components/Toaster/useToaster.js +32 -30
  10. package/lib/components/Toaster/useToaster.js.map +1 -1
  11. package/lib/components/Toaster/useToasterFocusManagement.js +85 -0
  12. package/lib/components/Toaster/useToasterFocusManagement.js.map +1 -0
  13. package/lib/state/useToaster.js +24 -6
  14. package/lib/state/useToaster.js.map +1 -1
  15. package/lib-commonjs/components/ToastContainer/useToastContainer.js +28 -11
  16. package/lib-commonjs/components/ToastContainer/useToastContainer.js.map +1 -1
  17. package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js +3 -3
  18. package/lib-commonjs/components/ToastContainer/useToastContainerStyles.styles.js.map +1 -1
  19. package/lib-commonjs/components/Toaster/useToastAnnounce.js +50 -0
  20. package/lib-commonjs/components/Toaster/useToastAnnounce.js.map +1 -0
  21. package/lib-commonjs/components/Toaster/useToaster.js +31 -29
  22. package/lib-commonjs/components/Toaster/useToaster.js.map +1 -1
  23. package/lib-commonjs/components/Toaster/useToasterFocusManagement.js +92 -0
  24. package/lib-commonjs/components/Toaster/useToasterFocusManagement.js.map +1 -0
  25. package/lib-commonjs/state/useToaster.js +24 -6
  26. package/lib-commonjs/state/useToaster.js.map +1 -1
  27. package/package.json +9 -8
@@ -18,11 +18,6 @@ export function useToaster(options = {}) {
18
18
  return shortcuts.focus(e);
19
19
  }
20
20
  });
21
- const tryRestoreFocus = React.useCallback(()=>{
22
- var _lastActiveElementRef_current;
23
- (_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();
24
- lastActiveElementRef.current = null;
25
- }, []);
26
21
  const pauseAllToasts = React.useCallback(()=>{
27
22
  toaster.visibleToasts.forEach((toastId)=>{
28
23
  var _toast_imperativeRef_current;
@@ -58,6 +53,28 @@ export function useToaster(options = {}) {
58
53
  }, [
59
54
  toaster
60
55
  ]);
56
+ const tryRestoreFocus = React.useCallback(()=>{
57
+ const mostRecentToast = getMostRecentVisibleToast();
58
+ if (mostRecentToast === null || mostRecentToast === void 0 ? void 0 : mostRecentToast.imperativeRef.current) {
59
+ mostRecentToast.imperativeRef.current.focus();
60
+ } else {
61
+ var _lastActiveElementRef_current;
62
+ (_lastActiveElementRef_current = lastActiveElementRef.current) === null || _lastActiveElementRef_current === void 0 ? void 0 : _lastActiveElementRef_current.focus();
63
+ lastActiveElementRef.current = null;
64
+ }
65
+ }, [
66
+ getMostRecentVisibleToast
67
+ ]);
68
+ const closeAllToasts = React.useCallback(()=>{
69
+ toaster.visibleToasts.forEach((toastId)=>{
70
+ const toast = toaster.toasts.get(toastId);
71
+ toast === null || toast === void 0 ? void 0 : toast.close();
72
+ });
73
+ tryRestoreFocus();
74
+ }, [
75
+ toaster,
76
+ tryRestoreFocus
77
+ ]);
61
78
  React.useEffect(()=>{
62
79
  if (!targetDocument) {
63
80
  return;
@@ -157,6 +174,7 @@ export function useToaster(options = {}) {
157
174
  toastsToRender,
158
175
  pauseAllToasts,
159
176
  playAllToasts,
160
- tryRestoreFocus
177
+ tryRestoreFocus,
178
+ closeAllToasts
161
179
  };
162
180
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["useToaster.ts"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createToaster } from './vanilla';\nimport type {\n CommonToastDetail,\n ShowToastEventDetail,\n Toast,\n ToastListenerMap,\n ToastPosition,\n ToasterId,\n ToasterOptions,\n} from './types';\nimport { EVENTS } from './constants';\n\nexport function useToaster<TElement extends HTMLElement = HTMLDivElement>(options: Partial<ToasterOptions> = {}) {\n const forceUpdate = useForceUpdate();\n const { toasterId: userToasterId, shortcuts } = options;\n // Currently the toaster options can never be changed at runtime\n const [toaster] = React.useState(() => createToaster(options));\n const { targetDocument } = useFluent();\n\n const lastActiveElementRef = React.useRef<HTMLElement | null>(null);\n\n const isCorrectToaster = useEventCallback((toasterId: ToasterId | undefined) => {\n return toasterId === userToasterId;\n });\n\n const isFocusShortcut = useEventCallback((e: KeyboardEvent) => {\n if (shortcuts?.focus) {\n return shortcuts.focus(e);\n }\n });\n\n const tryRestoreFocus = React.useCallback(() => {\n lastActiveElementRef.current?.focus();\n lastActiveElementRef.current = null;\n }, []);\n\n const pauseAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.pause();\n });\n }, [toaster]);\n\n const playAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.play();\n });\n }, [toaster]);\n\n const getMostRecentVisibleToast = React.useCallback(() => {\n return Array.from(toaster.visibleToasts).reduce((cur, next) => {\n const toast = toaster.toasts.get(next);\n if (!toast) {\n return cur;\n }\n\n if (!cur) {\n return toast;\n }\n\n if (cur.order < toast?.order) {\n return toast;\n }\n\n return cur;\n }, undefined as Toast | undefined);\n }, [toaster]);\n\n React.useEffect(() => {\n if (!targetDocument) {\n return;\n }\n\n const addToastListener = <TType extends keyof ToastListenerMap>(\n eventType: TType,\n callback: ToastListenerMap[TType],\n ) => {\n const listener: ToastListenerMap[TType] = (e: CustomEvent<CommonToastDetail>) => {\n if (!isCorrectToaster(e.detail.toasterId)) {\n return;\n }\n\n callback(e as CustomEvent<ShowToastEventDetail>);\n forceUpdate();\n };\n\n targetDocument.addEventListener(eventType, listener as () => void);\n return () => targetDocument.removeEventListener(eventType, listener as () => void);\n };\n\n const buildToast: ToastListenerMap[typeof EVENTS.show] = e => {\n toaster.buildToast(e.detail, forceUpdate);\n };\n\n const dismissToast: ToastListenerMap[typeof EVENTS.dismiss] = e => {\n toaster.dismissToast(e.detail.toastId);\n };\n\n const updateToast: ToastListenerMap[typeof EVENTS.update] = e => {\n toaster.updateToast(e.detail);\n };\n\n const dismissAllToasts: ToastListenerMap[typeof EVENTS.dismissAll] = e => {\n toaster.dismissAllToasts();\n };\n\n const pauseToast: ToastListenerMap[typeof EVENTS.pause] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.pause();\n }\n };\n\n const playToast: ToastListenerMap[typeof EVENTS.play] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.play();\n }\n };\n\n const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);\n const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);\n const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);\n const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);\n const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);\n const cleanupPlayListener = addToastListener(EVENTS.play, playToast);\n\n const focusShortcutListener = (e: KeyboardEvent) => {\n if (isFocusShortcut(e)) {\n pauseAllToasts();\n const mostRecentToast = getMostRecentVisibleToast();\n\n if (mostRecentToast) {\n lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement)\n ? targetDocument.activeElement\n : null;\n mostRecentToast.imperativeRef.current?.focus();\n }\n }\n };\n\n targetDocument.addEventListener('keydown', focusShortcutListener);\n\n return () => {\n cleanupBuildListener();\n cleanupDismissAllListener();\n cleanupUpdateListener();\n cleanupDismissListener();\n cleanupPauseListener();\n cleanupPlayListener();\n\n targetDocument.removeEventListener('keydown', focusShortcutListener);\n };\n }, [\n toaster,\n forceUpdate,\n targetDocument,\n isCorrectToaster,\n pauseAllToasts,\n getMostRecentVisibleToast,\n isFocusShortcut,\n ]);\n\n const toastsToRender = (() => {\n if (!toaster) {\n return new Map<ToastPosition, Toast[]>();\n }\n\n const toRender = new Map<ToastPosition, Toast[]>();\n const toasts = Array.from(toaster.toasts.values());\n\n toasts.forEach(toast => {\n const { position } = toast;\n toRender.has(position) || toRender.set(position, []);\n if (position.startsWith('bottom')) {\n toRender.get(position)!.push(toast);\n } else {\n toRender.get(position)!.unshift(toast);\n }\n });\n\n return toRender;\n })();\n\n return {\n isToastVisible: toaster.isToastVisible,\n toastsToRender,\n pauseAllToasts,\n playAllToasts,\n tryRestoreFocus,\n };\n}\n"],"names":["React","isHTMLElement","useEventCallback","useForceUpdate","useFluent_unstable","useFluent","createToaster","EVENTS","useToaster","options","forceUpdate","toasterId","userToasterId","shortcuts","toaster","useState","targetDocument","lastActiveElementRef","useRef","isCorrectToaster","isFocusShortcut","e","focus","tryRestoreFocus","useCallback","current","pauseAllToasts","visibleToasts","forEach","toastId","toast","toasts","get","imperativeRef","pause","playAllToasts","play","getMostRecentVisibleToast","Array","from","reduce","cur","next","order","undefined","useEffect","addToastListener","eventType","callback","listener","detail","addEventListener","removeEventListener","buildToast","dismissToast","updateToast","dismissAllToasts","pauseToast","playToast","cleanupBuildListener","show","cleanupUpdateListener","update","cleanupDismissListener","dismiss","cleanupDismissAllListener","dismissAll","cleanupPauseListener","cleanupPlayListener","focusShortcutListener","mostRecentToast","activeElement","toastsToRender","Map","toRender","values","position","has","set","startsWith","push","unshift","isToastVisible"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC5F,SAASC,sBAAsBC,SAAS,QAAQ,kCAAkC;AAClF,SAASC,aAAa,QAAQ,YAAY;AAU1C,SAASC,M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,OAAO,cAArC6C,oDAAAA,KAAAA,IAAAA,uCAAuChD;gBACzC,CAAC;YACH,CAAC;QACH;QAEAN,eAAemC,gBAAgB,CAAC,WAAWkB;QAE3C,OAAO,IAAM;YACXV;YACAM;YACAJ;YACAE;YACAI;YACAC;YAEApD,eAAeoC,mBAAmB,CAAC,WAAWiB;QAChD;IACF,GAAG;QACDvD;QACAJ;QACAM;QACAG;QACAO;QACAW;QACAjB;KACD;IAED,MAAMoD,iBAAiB,AAAC,CAAA,IAAM;QAC5B,IAAI,CAAC1D,SAAS;YACZ,OAAO,IAAI2D;QACb,CAAC;QAED,MAAMC,WAAW,IAAID;QACrB,MAAM1C,SAASO,MAAMC,IAAI,CAACzB,QAAQiB,MAAM,CAAC4C,MAAM;QAE/C5C,OAAOH,OAAO,CAACE,CAAAA,QAAS;YACtB,MAAM,EAAE8C,SAAQ,EAAE,GAAG9C;YACrB4C,SAASG,GAAG,CAACD,aAAaF,SAASI,GAAG,CAACF,UAAU,EAAE;YACnD,IAAIA,SAASG,UAAU,CAAC,WAAW;gBACjCL,SAAS1C,GAAG,CAAC4C,UAAWI,IAAI,CAAClD;YAC/B,OAAO;gBACL4C,SAAS1C,GAAG,CAAC4C,UAAWK,OAAO,CAACnD;YAClC,CAAC;QACH;QAEA,OAAO4C;IACT,CAAA;IAEA,OAAO;QACLQ,gBAAgBpE,QAAQoE,cAAc;QACtCV;QACA9C;QACAS;QACAZ;IACF;AACF,CAAC"}
1
+ {"version":3,"sources":["useToaster.ts"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement, useEventCallback, useForceUpdate } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { createToaster } from './vanilla';\nimport type {\n CommonToastDetail,\n ShowToastEventDetail,\n Toast,\n ToastListenerMap,\n ToastPosition,\n ToasterId,\n ToasterOptions,\n} from './types';\nimport { EVENTS } from './constants';\n\nexport function useToaster<TElement extends HTMLElement = HTMLDivElement>(options: Partial<ToasterOptions> = {}) {\n const forceUpdate = useForceUpdate();\n const { toasterId: userToasterId, shortcuts } = options;\n // Currently the toaster options can never be changed at runtime\n const [toaster] = React.useState(() => createToaster(options));\n const { targetDocument } = useFluent();\n\n const lastActiveElementRef = React.useRef<HTMLElement | null>(null);\n\n const isCorrectToaster = useEventCallback((toasterId: ToasterId | undefined) => {\n return toasterId === userToasterId;\n });\n\n const isFocusShortcut = useEventCallback((e: KeyboardEvent) => {\n if (shortcuts?.focus) {\n return shortcuts.focus(e);\n }\n });\n\n const pauseAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.pause();\n });\n }, [toaster]);\n\n const playAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.imperativeRef.current?.play();\n });\n }, [toaster]);\n\n const getMostRecentVisibleToast = React.useCallback(() => {\n return Array.from(toaster.visibleToasts).reduce((cur, next) => {\n const toast = toaster.toasts.get(next);\n if (!toast) {\n return cur;\n }\n\n if (!cur) {\n return toast;\n }\n\n if (cur.order < toast?.order) {\n return toast;\n }\n\n return cur;\n }, undefined as Toast | undefined);\n }, [toaster]);\n\n const tryRestoreFocus = React.useCallback(() => {\n const mostRecentToast = getMostRecentVisibleToast();\n if (mostRecentToast?.imperativeRef.current) {\n mostRecentToast.imperativeRef.current.focus();\n } else {\n lastActiveElementRef.current?.focus();\n lastActiveElementRef.current = null;\n }\n }, [getMostRecentVisibleToast]);\n\n const closeAllToasts = React.useCallback(() => {\n toaster.visibleToasts.forEach(toastId => {\n const toast = toaster.toasts.get(toastId);\n toast?.close();\n });\n\n tryRestoreFocus();\n }, [toaster, tryRestoreFocus]);\n\n React.useEffect(() => {\n if (!targetDocument) {\n return;\n }\n\n const addToastListener = <TType extends keyof ToastListenerMap>(\n eventType: TType,\n callback: ToastListenerMap[TType],\n ) => {\n const listener: ToastListenerMap[TType] = (e: CustomEvent<CommonToastDetail>) => {\n if (!isCorrectToaster(e.detail.toasterId)) {\n return;\n }\n\n callback(e as CustomEvent<ShowToastEventDetail>);\n forceUpdate();\n };\n\n targetDocument.addEventListener(eventType, listener as () => void);\n return () => targetDocument.removeEventListener(eventType, listener as () => void);\n };\n\n const buildToast: ToastListenerMap[typeof EVENTS.show] = e => {\n toaster.buildToast(e.detail, forceUpdate);\n };\n\n const dismissToast: ToastListenerMap[typeof EVENTS.dismiss] = e => {\n toaster.dismissToast(e.detail.toastId);\n };\n\n const updateToast: ToastListenerMap[typeof EVENTS.update] = e => {\n toaster.updateToast(e.detail);\n };\n\n const dismissAllToasts: ToastListenerMap[typeof EVENTS.dismissAll] = e => {\n toaster.dismissAllToasts();\n };\n\n const pauseToast: ToastListenerMap[typeof EVENTS.pause] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.pause();\n }\n };\n\n const playToast: ToastListenerMap[typeof EVENTS.play] = e => {\n const toast = toaster.toasts.get(e.detail.toastId);\n if (toast) {\n toast.imperativeRef.current?.play();\n }\n };\n\n const cleanupBuildListener = addToastListener(EVENTS.show, buildToast);\n const cleanupUpdateListener = addToastListener(EVENTS.update, updateToast);\n const cleanupDismissListener = addToastListener(EVENTS.dismiss, dismissToast);\n const cleanupDismissAllListener = addToastListener(EVENTS.dismissAll, dismissAllToasts);\n const cleanupPauseListener = addToastListener(EVENTS.pause, pauseToast);\n const cleanupPlayListener = addToastListener(EVENTS.play, playToast);\n\n const focusShortcutListener = (e: KeyboardEvent) => {\n if (isFocusShortcut(e)) {\n pauseAllToasts();\n const mostRecentToast = getMostRecentVisibleToast();\n\n if (mostRecentToast) {\n lastActiveElementRef.current = isHTMLElement(targetDocument.activeElement)\n ? targetDocument.activeElement\n : null;\n mostRecentToast.imperativeRef.current?.focus();\n }\n }\n };\n\n targetDocument.addEventListener('keydown', focusShortcutListener);\n\n return () => {\n cleanupBuildListener();\n cleanupDismissAllListener();\n cleanupUpdateListener();\n cleanupDismissListener();\n cleanupPauseListener();\n cleanupPlayListener();\n\n targetDocument.removeEventListener('keydown', focusShortcutListener);\n };\n }, [\n toaster,\n forceUpdate,\n targetDocument,\n isCorrectToaster,\n pauseAllToasts,\n getMostRecentVisibleToast,\n isFocusShortcut,\n ]);\n\n const toastsToRender = (() => {\n if (!toaster) {\n return new Map<ToastPosition, Toast[]>();\n }\n\n const toRender = new Map<ToastPosition, Toast[]>();\n const toasts = Array.from(toaster.toasts.values());\n\n toasts.forEach(toast => {\n const { position } = toast;\n toRender.has(position) || toRender.set(position, []);\n if (position.startsWith('bottom')) {\n toRender.get(position)!.push(toast);\n } else {\n toRender.get(position)!.unshift(toast);\n }\n });\n\n return toRender;\n })();\n\n return {\n isToastVisible: toaster.isToastVisible,\n toastsToRender,\n pauseAllToasts,\n playAllToasts,\n tryRestoreFocus,\n closeAllToasts,\n };\n}\n"],"names":["React","isHTMLElement","useEventCallback","useForceUpdate","useFluent_unstable","useFluent","createToaster","EVENTS","useToaster","options","forceUpdate","toasterId","userToasterId","shortcuts","toaster","useState","targetDocument","lastActiveElementRef","useRef","isCorrectToaster","isFocusShortcut","e","focus","pauseAllToasts","useCallback","visibleToasts","forEach","toastId","toast","toasts","get","imperativeRef","current","pause","playAllToasts","play","getMostRecentVisibleToast","Array","from","reduce","cur","next","order","undefined","tryRestoreFocus","mostRecentToast","closeAllToasts","close","useEffect","addToastListener","eventType","callback","listener","detail","addEventListener","removeEventListener","buildToast","dismissToast","updateToast","dismissAllToasts","pauseToast","playToast","cleanupBuildListener","show","cleanupUpdateListener","update","cleanupDismissListener","dismiss","cleanupDismissAllListener","dismissAll","cleanupPauseListener","cleanupPlayListener","focusShortcutListener","activeElement","toastsToRender","Map","toRender","values","position","has","set","startsWith","push","unshift","isToastVisible"],"mappings":"AAAA,YAAYA,WAAW,QAAQ;AAC/B,SAASC,aAAa,EAAEC,gBAAgB,EAAEC,cAAc,QAAQ,4BAA4B;AAC5F,SAASC,sBAAsB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LgD,SAAS9C,GAAG,CAACgD,UAAWK,OAAO,CAACvD;YAClC,CAAC;QACH;QAEA,OAAOgD;IACT,CAAA;IAEA,OAAO;QACLQ,gBAAgBtE,QAAQsE,cAAc;QACtCV;QACAnD;QACAW;QACAU;QACAE;IACF;AACF,CAAC"}
@@ -10,8 +10,9 @@ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildc
10
10
  const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
11
  const _reactUtilities = require("@fluentui/react-utilities");
12
12
  const _reactSharedContexts = require("@fluentui/react-shared-contexts");
13
- const _timer = require("../Timer/Timer");
13
+ const _keyboardKeys = require("@fluentui/keyboard-keys");
14
14
  const _reactTabster = require("@fluentui/react-tabster");
15
+ const _timer = require("../Timer/Timer");
15
16
  const intentPolitenessMap = {
16
17
  success: 'assertive',
17
18
  warning: 'assertive',
@@ -27,6 +28,16 @@ const useToastContainer_unstable = (props, ref)=>{
27
28
  const [running, setRunning] = _react.useState(false);
28
29
  const imperativePauseRef = _react.useRef(false);
29
30
  const focusedToastBeforeClose = _react.useRef(false);
31
+ const focusableGroupAttribute = (0, _reactTabster.useFocusableGroup)({
32
+ tabBehavior: 'limited-trap-focus',
33
+ // Users should only use Tab to focus into the toast
34
+ // Escape is already reserved to dismiss all toasts
35
+ ignoreDefaultKeydown: {
36
+ Tab: true,
37
+ Escape: true,
38
+ Enter: true
39
+ }
40
+ });
30
41
  const close = (0, _reactUtilities.useEventCallback)(()=>{
31
42
  var _toastRef_current;
32
43
  const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;
@@ -58,18 +69,12 @@ const useToastContainer_unstable = (props, ref)=>{
58
69
  setRunning(true);
59
70
  }
60
71
  });
61
- const { findFirstFocusable } = (0, _reactTabster.useFocusFinders)();
62
72
  _react.useImperativeHandle(imperativeRef, ()=>({
63
73
  focus: ()=>{
64
74
  if (!toastRef.current) {
65
75
  return;
66
76
  }
67
- const firstFocusable = findFirstFocusable(toastRef.current);
68
- if (firstFocusable) {
69
- firstFocusable.focus();
70
- } else {
71
- toastRef.current.focus();
72
- }
77
+ toastRef.current.focus();
73
78
  },
74
79
  play: ()=>{
75
80
  imperativePauseRef.current = false;
@@ -142,12 +147,23 @@ const useToastContainer_unstable = (props, ref)=>{
142
147
  play();
143
148
  userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);
144
149
  });
150
+ const { findFirstFocusable , findLastFocusable } = (0, _reactTabster.useFocusFinders)();
145
151
  const onKeyDown = (0, _reactUtilities.useEventCallback)((e)=>{
146
152
  var _userRootSlot_onKeyDown;
147
- if (e.key === 'Escape') {
153
+ if (e.key === _keyboardKeys.Delete) {
148
154
  e.preventDefault();
149
155
  close();
150
156
  }
157
+ if (e.key === _keyboardKeys.Tab && e.currentTarget === e.target) {
158
+ e.preventDefault();
159
+ if (e.shiftKey) {
160
+ var _findLastFocusable;
161
+ (_findLastFocusable = findLastFocusable(e.currentTarget)) === null || _findLastFocusable === void 0 ? void 0 : _findLastFocusable.focus();
162
+ } else {
163
+ var _findFirstFocusable;
164
+ (_findFirstFocusable = findFirstFocusable(e.currentTarget)) === null || _findFirstFocusable === void 0 ? void 0 : _findFirstFocusable.focus();
165
+ }
166
+ }
151
167
  userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onKeyDown = userRootSlot.onKeyDown) === null || _userRootSlot_onKeyDown === void 0 ? void 0 : _userRootSlot_onKeyDown.call(userRootSlot, e);
152
168
  });
153
169
  _react.useEffect(()=>{
@@ -194,12 +210,13 @@ const useToastContainer_unstable = (props, ref)=>{
194
210
  root: (0, _reactUtilities.getNativeElementProps)('div', {
195
211
  ref: (0, _reactUtilities.useMergedRefs)(ref, toastRef, toastAnimationRef),
196
212
  children,
197
- tabIndex: -1,
198
- role: 'group',
213
+ tabIndex: 0,
214
+ role: 'listitem',
199
215
  'aria-labelledby': titleId,
200
216
  'aria-describedby': bodyId,
201
217
  ...rest,
202
218
  ...userRootSlot,
219
+ ...focusableGroupAttribute,
203
220
  onMouseEnter,
204
221
  onMouseLeave,
205
222
  onKeyDown
@@ -1 +1 @@
1
- {"version":3,"sources":["useToastContainer.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useMergedRefs, useEventCallback, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { Timer } from '../Timer/Timer';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nconst intentPolitenessMap = {\n success: 'assertive',\n warning: 'assertive',\n error: 'assertive',\n info: 'polite'\n};\n/**\n * Create the state required to render ToastContainer.\n *\n * The returned state can be modified with hooks such as useToastContainerStyles_unstable,\n * before being passed to renderToastContainer_unstable.\n *\n * @param props - props from this instance of ToastContainer\n * @param ref - reference to root HTMLElement of ToastContainer\n */ export const useToastContainer_unstable = (props, ref)=>{\n const { visible , children , close: closeProp , remove , updateId , announce , data , timeout: timerTimeout , politeness: desiredPoliteness , intent ='info' , pauseOnHover , pauseOnWindowBlur , imperativeRef , tryRestoreFocus , ...rest } = props;\n const titleId = useId('toast-title');\n const bodyId = useId('toast-body');\n const toastRef = React.useRef(null);\n const { targetDocument } = useFluent_unstable();\n const [running, setRunning] = React.useState(false);\n const imperativePauseRef = React.useRef(false);\n const focusedToastBeforeClose = React.useRef(false);\n const close = useEventCallback(()=>{\n var _toastRef_current;\n const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;\n if (activeElement && ((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains(activeElement))) {\n focusedToastBeforeClose.current = true;\n }\n closeProp();\n });\n const onStatusChange = useEventCallback((status)=>{\n var _props_onStatusChange;\n return (_props_onStatusChange = props.onStatusChange) === null || _props_onStatusChange === void 0 ? void 0 : _props_onStatusChange.call(props, null, {\n status,\n ...props\n });\n });\n const pause = useEventCallback(()=>setRunning(false));\n const play = useEventCallback(()=>{\n var _toastRef_current;\n if (imperativePauseRef.current) {\n return;\n }\n var _targetDocument_activeElement;\n const containsActive = !!((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains((_targetDocument_activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) !== null && _targetDocument_activeElement !== void 0 ? _targetDocument_activeElement : null));\n if (timerTimeout < 0) {\n setRunning(true);\n return;\n }\n if (!containsActive) {\n setRunning(true);\n }\n });\n const { findFirstFocusable } = useFocusFinders();\n React.useImperativeHandle(imperativeRef, ()=>({\n focus: ()=>{\n if (!toastRef.current) {\n return;\n }\n const firstFocusable = findFirstFocusable(toastRef.current);\n if (firstFocusable) {\n firstFocusable.focus();\n } else {\n toastRef.current.focus();\n }\n },\n play: ()=>{\n imperativePauseRef.current = false;\n play();\n },\n pause: ()=>{\n imperativePauseRef.current = true;\n pause();\n }\n }));\n React.useEffect(()=>{\n return ()=>onStatusChange('unmounted');\n }, [\n onStatusChange\n ]);\n React.useEffect(()=>{\n if (!targetDocument) {\n return;\n }\n if (pauseOnWindowBlur) {\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.addEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.addEventListener('blur', pause);\n return ()=>{\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.removeEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.removeEventListener('blur', pause);\n };\n }\n }, [\n targetDocument,\n pause,\n play,\n pauseOnWindowBlur\n ]);\n // It's impossible to animate to height: auto in CSS, the actual pixel value must be known\n // Get the height of the toast before animation styles have been applied and set a CSS\n // variable with its height. The CSS variable will be used by the styles\n const onTransitionEntering = ()=>{\n if (!toastRef.current) {\n return;\n }\n const element = toastRef.current;\n element.style.setProperty('--fui-toast-height', `${element.scrollHeight}px`);\n };\n // Users never actually use ToastContainer as a JSX but imperatively through useToastContainerController\n const userRootSlot = data.root;\n // Using a ref callback here because addEventListener supports `once`\n const toastAnimationRef = React.useCallback((el)=>{\n if (el && toastRef.current) {\n toastRef.current.addEventListener('animationend', ()=>{\n // start toast once it's fully animated in\n play();\n onStatusChange('visible');\n }, {\n once: true\n });\n }\n }, [\n play,\n onStatusChange\n ]);\n const onMouseEnter = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n pause();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const onMouseLeave = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n play();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const onKeyDown = useEventCallback((e)=>{\n var _userRootSlot_onKeyDown;\n if (e.key === 'Escape') {\n e.preventDefault();\n close();\n }\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onKeyDown = userRootSlot.onKeyDown) === null || _userRootSlot_onKeyDown === void 0 ? void 0 : _userRootSlot_onKeyDown.call(userRootSlot, e);\n });\n React.useEffect(()=>{\n var _toastRef_current;\n if (!visible) {\n return;\n }\n const politeness = desiredPoliteness !== null && desiredPoliteness !== void 0 ? desiredPoliteness : intentPolitenessMap[intent];\n var _toastRef_current_textContent;\n announce((_toastRef_current_textContent = (_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.textContent) !== null && _toastRef_current_textContent !== void 0 ? _toastRef_current_textContent : '', {\n politeness\n });\n }, [\n announce,\n desiredPoliteness,\n toastRef,\n visible,\n updateId,\n intent\n ]);\n React.useEffect(()=>{\n return ()=>{\n if (focusedToastBeforeClose.current) {\n focusedToastBeforeClose.current = false;\n tryRestoreFocus();\n }\n };\n }, [\n tryRestoreFocus\n ]);\n return {\n components: {\n timer: Timer,\n root: 'div'\n },\n timer: resolveShorthand({\n key: updateId,\n onTimeout: close,\n running,\n timeout: timerTimeout !== null && timerTimeout !== void 0 ? timerTimeout : -1\n }, {\n required: true\n }),\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, toastRef, toastAnimationRef),\n children,\n tabIndex: -1,\n role: 'group',\n 'aria-labelledby': titleId,\n 'aria-describedby': bodyId,\n ...rest,\n ...userRootSlot,\n onMouseEnter,\n onMouseLeave,\n onKeyDown\n }),\n timerTimeout,\n transitionTimeout: 500,\n running,\n visible,\n remove,\n close,\n onTransitionEntering,\n updateId,\n nodeRef: toastRef,\n intent,\n titleId,\n bodyId\n };\n};\n"],"names":["useToastContainer_unstable","intentPolitenessMap","success","warning","error","info","props","ref","visible","children","close","closeProp","remove","updateId","announce","data","timeout","timerTimeout","politeness","desiredPoliteness","intent","pauseOnHover","pauseOnWindowBlur","imperativeRef","tryRestoreFocus","rest","titleId","useId","bodyId","toastRef","React","useRef","targetDocument","useFluent_unstable","running","setRunning","useState","imperativePauseRef","focusedToastBeforeClose","useEventCallback","_toastRef_current","activeElement","current","contains","onStatusChange","status","_props_onStatusChange","call","pause","play","_targetDocument_activeElement","containsActive","findFirstFocusable","useFocusFinders","useImperativeHandle","focus","firstFocusable","useEffect","_targetDocument_defaultView","_targetDocument_defaultView1","defaultView","addEventListener","removeEventListener","onTransitionEntering","element","style","setProperty","scrollHeight","userRootSlot","root","toastAnimationRef","useCallback","el","once","onMouseEnter","e","_userRootSlot_onMouseEnter","onMouseLeave","onKeyDown","_userRootSlot_onKeyDown","key","preventDefault","_toastRef_current_textContent","textContent","components","timer","Timer","resolveShorthand","onTimeout","required","getNativeElementProps","useMergedRefs","tabIndex","role","transitionTimeout","nodeRef"],"mappings":";;;;+BAmBiBA;;aAAAA;;;6DAnBM;gCACyE;qCAC7D;uBACb;8BACU;AAChC,MAAMC,sBAAsB;IACxBC,SAAS;IACTC,SAAS;IACTC,OAAO;IACPC,MAAM;AACV;AASW,MAAML,6BAA6B,CAACM,OAAOC,MAAM;IACxD,MAAM,EAAEC,QAAO,EAAGC,SAAQ,EAAGC,OAAOC,UAAS,EAAGC,OAAM,EAAGC,SAAQ,EAAGC,SAAQ,EAAGC,KAAI,EAAGC,SAASC,aAAY,EAAGC,YAAYC,kBAAiB,EAAGC,QAAQ,OAAM,EAAGC,aAAY,EAAGC,kBAAiB,EAAGC,cAAa,EAAGC,gBAAe,EAAG,GAAGC,MAAM,GAAGnB;IAChP,MAAMoB,UAAUC,IAAAA,qBAAK,EAAC;IACtB,MAAMC,SAASD,IAAAA,qBAAK,EAAC;IACrB,MAAME,WAAWC,OAAMC,MAAM,CAAC,IAAI;IAClC,MAAM,EAAEC,eAAc,EAAG,GAAGC,IAAAA,uCAAkB;IAC9C,MAAM,CAACC,SAASC,WAAW,GAAGL,OAAMM,QAAQ,CAAC,KAAK;IAClD,MAAMC,qBAAqBP,OAAMC,MAAM,CAAC,KAAK;IAC7C,MAAMO,0BAA0BR,OAAMC,MAAM,CAAC,KAAK;IAClD,MAAMrB,QAAQ6B,IAAAA,gCAAgB,EAAC,IAAI;QAC/B,IAAIC;QACJ,MAAMC,gBAAgBT,mBAAmB,IAAI,IAAIA,mBAAmB,KAAK,IAAI,KAAK,IAAIA,eAAeS,aAAa;QAClH,IAAIA,iBAAkB,CAAA,AAACD,CAAAA,oBAAoBX,SAASa,OAAO,AAAD,MAAO,IAAI,IAAIF,sBAAsB,KAAK,IAAI,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B,oBAAoBE;YACpB,GAAGH,IAAI;YACP,GAAG2C,YAAY;YACfM;YACAG;YACAC;QACJ;QACA7D;QACA6E,mBAAmB;QACnB5D;QACA1B;QACAI;QACAF;QACAqD;QACAlD;QACAkF,SAASlE;QACTT;QACAM;QACAE;IACJ;AACJ"}
1
+ {"version":3,"sources":["useToastContainer.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, useMergedRefs, useEventCallback, resolveShorthand, useId } from '@fluentui/react-utilities';\nimport { useFluent_unstable } from '@fluentui/react-shared-contexts';\nimport { Delete, Tab } from '@fluentui/keyboard-keys';\nimport { useFocusableGroup, useFocusFinders } from '@fluentui/react-tabster';\nimport { Timer } from '../Timer/Timer';\nconst intentPolitenessMap = {\n success: 'assertive',\n warning: 'assertive',\n error: 'assertive',\n info: 'polite'\n};\n/**\n * Create the state required to render ToastContainer.\n *\n * The returned state can be modified with hooks such as useToastContainerStyles_unstable,\n * before being passed to renderToastContainer_unstable.\n *\n * @param props - props from this instance of ToastContainer\n * @param ref - reference to root HTMLElement of ToastContainer\n */ export const useToastContainer_unstable = (props, ref)=>{\n const { visible , children , close: closeProp , remove , updateId , announce , data , timeout: timerTimeout , politeness: desiredPoliteness , intent ='info' , pauseOnHover , pauseOnWindowBlur , imperativeRef , tryRestoreFocus , ...rest } = props;\n const titleId = useId('toast-title');\n const bodyId = useId('toast-body');\n const toastRef = React.useRef(null);\n const { targetDocument } = useFluent_unstable();\n const [running, setRunning] = React.useState(false);\n const imperativePauseRef = React.useRef(false);\n const focusedToastBeforeClose = React.useRef(false);\n const focusableGroupAttribute = useFocusableGroup({\n tabBehavior: 'limited-trap-focus',\n // Users should only use Tab to focus into the toast\n // Escape is already reserved to dismiss all toasts\n ignoreDefaultKeydown: {\n Tab: true,\n Escape: true,\n Enter: true\n }\n });\n const close = useEventCallback(()=>{\n var _toastRef_current;\n const activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement;\n if (activeElement && ((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains(activeElement))) {\n focusedToastBeforeClose.current = true;\n }\n closeProp();\n });\n const onStatusChange = useEventCallback((status)=>{\n var _props_onStatusChange;\n return (_props_onStatusChange = props.onStatusChange) === null || _props_onStatusChange === void 0 ? void 0 : _props_onStatusChange.call(props, null, {\n status,\n ...props\n });\n });\n const pause = useEventCallback(()=>setRunning(false));\n const play = useEventCallback(()=>{\n var _toastRef_current;\n if (imperativePauseRef.current) {\n return;\n }\n var _targetDocument_activeElement;\n const containsActive = !!((_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.contains((_targetDocument_activeElement = targetDocument === null || targetDocument === void 0 ? void 0 : targetDocument.activeElement) !== null && _targetDocument_activeElement !== void 0 ? _targetDocument_activeElement : null));\n if (timerTimeout < 0) {\n setRunning(true);\n return;\n }\n if (!containsActive) {\n setRunning(true);\n }\n });\n React.useImperativeHandle(imperativeRef, ()=>({\n focus: ()=>{\n if (!toastRef.current) {\n return;\n }\n toastRef.current.focus();\n },\n play: ()=>{\n imperativePauseRef.current = false;\n play();\n },\n pause: ()=>{\n imperativePauseRef.current = true;\n pause();\n }\n }));\n React.useEffect(()=>{\n return ()=>onStatusChange('unmounted');\n }, [\n onStatusChange\n ]);\n React.useEffect(()=>{\n if (!targetDocument) {\n return;\n }\n if (pauseOnWindowBlur) {\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.addEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.addEventListener('blur', pause);\n return ()=>{\n var _targetDocument_defaultView, _targetDocument_defaultView1;\n (_targetDocument_defaultView = targetDocument.defaultView) === null || _targetDocument_defaultView === void 0 ? void 0 : _targetDocument_defaultView.removeEventListener('focus', play);\n (_targetDocument_defaultView1 = targetDocument.defaultView) === null || _targetDocument_defaultView1 === void 0 ? void 0 : _targetDocument_defaultView1.removeEventListener('blur', pause);\n };\n }\n }, [\n targetDocument,\n pause,\n play,\n pauseOnWindowBlur\n ]);\n // It's impossible to animate to height: auto in CSS, the actual pixel value must be known\n // Get the height of the toast before animation styles have been applied and set a CSS\n // variable with its height. The CSS variable will be used by the styles\n const onTransitionEntering = ()=>{\n if (!toastRef.current) {\n return;\n }\n const element = toastRef.current;\n element.style.setProperty('--fui-toast-height', `${element.scrollHeight}px`);\n };\n // Users never actually use ToastContainer as a JSX but imperatively through useToastContainerController\n const userRootSlot = data.root;\n // Using a ref callback here because addEventListener supports `once`\n const toastAnimationRef = React.useCallback((el)=>{\n if (el && toastRef.current) {\n toastRef.current.addEventListener('animationend', ()=>{\n // start toast once it's fully animated in\n play();\n onStatusChange('visible');\n }, {\n once: true\n });\n }\n }, [\n play,\n onStatusChange\n ]);\n const onMouseEnter = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n pause();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const onMouseLeave = useEventCallback((e)=>{\n var _userRootSlot_onMouseEnter;\n play();\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onMouseEnter = userRootSlot.onMouseEnter) === null || _userRootSlot_onMouseEnter === void 0 ? void 0 : _userRootSlot_onMouseEnter.call(userRootSlot, e);\n });\n const { findFirstFocusable , findLastFocusable } = useFocusFinders();\n const onKeyDown = useEventCallback((e)=>{\n var _userRootSlot_onKeyDown;\n if (e.key === Delete) {\n e.preventDefault();\n close();\n }\n if (e.key === Tab && e.currentTarget === e.target) {\n e.preventDefault();\n if (e.shiftKey) {\n var _findLastFocusable;\n (_findLastFocusable = findLastFocusable(e.currentTarget)) === null || _findLastFocusable === void 0 ? void 0 : _findLastFocusable.focus();\n } else {\n var _findFirstFocusable;\n (_findFirstFocusable = findFirstFocusable(e.currentTarget)) === null || _findFirstFocusable === void 0 ? void 0 : _findFirstFocusable.focus();\n }\n }\n userRootSlot === null || userRootSlot === void 0 ? void 0 : (_userRootSlot_onKeyDown = userRootSlot.onKeyDown) === null || _userRootSlot_onKeyDown === void 0 ? void 0 : _userRootSlot_onKeyDown.call(userRootSlot, e);\n });\n React.useEffect(()=>{\n var _toastRef_current;\n if (!visible) {\n return;\n }\n const politeness = desiredPoliteness !== null && desiredPoliteness !== void 0 ? desiredPoliteness : intentPolitenessMap[intent];\n var _toastRef_current_textContent;\n announce((_toastRef_current_textContent = (_toastRef_current = toastRef.current) === null || _toastRef_current === void 0 ? void 0 : _toastRef_current.textContent) !== null && _toastRef_current_textContent !== void 0 ? _toastRef_current_textContent : '', {\n politeness\n });\n }, [\n announce,\n desiredPoliteness,\n toastRef,\n visible,\n updateId,\n intent\n ]);\n React.useEffect(()=>{\n return ()=>{\n if (focusedToastBeforeClose.current) {\n focusedToastBeforeClose.current = false;\n tryRestoreFocus();\n }\n };\n }, [\n tryRestoreFocus\n ]);\n return {\n components: {\n timer: Timer,\n root: 'div'\n },\n timer: resolveShorthand({\n key: updateId,\n onTimeout: close,\n running,\n timeout: timerTimeout !== null && timerTimeout !== void 0 ? timerTimeout : -1\n }, {\n required: true\n }),\n root: getNativeElementProps('div', {\n ref: useMergedRefs(ref, toastRef, toastAnimationRef),\n children,\n tabIndex: 0,\n role: 'listitem',\n 'aria-labelledby': titleId,\n 'aria-describedby': bodyId,\n ...rest,\n ...userRootSlot,\n ...focusableGroupAttribute,\n onMouseEnter,\n onMouseLeave,\n onKeyDown\n }),\n timerTimeout,\n transitionTimeout: 500,\n running,\n visible,\n remove,\n close,\n onTransitionEntering,\n updateId,\n nodeRef: toastRef,\n intent,\n titleId,\n bodyId\n };\n};\n"],"names":["useToastContainer_unstable","intentPolitenessMap","success","warning","error","info","props","ref","visible","children","close","closeProp","remove","updateId","announce","data","timeout","timerTimeout","politeness","desiredPoliteness","intent","pauseOnHover","pauseOnWindowBlur","imperativeRef","tryRestoreFocus","rest","titleId","useId","bodyId","toastRef","React","useRef","targetDocument","useFluent_unstable","running","setRunning","useState","imperativePauseRef","focusedToastBeforeClose","focusableGroupAttribute","useFocusableGroup","tabBehavior","ignoreDefaultKeydown","Tab","Escape","Enter","useEventCallback","_toastRef_current","activeElement","current","contains","onStatusChange","status","_props_onStatusChange","call","pause","play","_targetDocument_activeElement","containsActive","useImperativeHandle","focus","useEffect","_targetDocument_defaultView","_targetDocument_defaultView1","defaultView","addEventListener","removeEventListener","onTransitionEntering","element","style","setProperty","scrollHeight","userRootSlot","root","toastAnimationRef","useCallback","el","once","onMouseEnter","e","_userRootSlot_onMouseEnter","onMouseLeave","findFirstFocusable","findLastFocusable","useFocusFinders","onKeyDown","_userRootSlot_onKeyDown","key","Delete","preventDefault","currentTarget","target","shiftKey","_findLastFocusable","_findFirstFocusable","_toastRef_current_textContent","textContent","components","timer","Timer","resolveShorthand","onTimeout","required","getNativeElementProps","useMergedRefs","tabIndex","role","transitionTimeout","nodeRef"],"mappings":";;;;+BAoBiBA;;aAAAA;;;6DApBM;gCACyE;qCAC7D;8BACP;8BACuB;uBAC7B;AACtB,MAAMC,sBAAsB;IACxBC,SAAS;IACTC,SAAS;IACTC,OAAO;IACPC,MAAM;AACV;AASW,MAAML,6BAA6B,CAACM,OAAOC,MAAM;IACxD,MAAM,EAAEC,QAAO,EAAGC,SAAQ,EAAGC,OAAOC,UAAS,EAAGC,OAAM,EAAGC,SAAQ,EAAGC,SAAQ,EAAGC,KAAI,EAAGC,SAASC,aAAY,EAAGC,YAAYC,kBAAiB,EAAGC,QAAQ,OAAM,EAAGC,aAAY,EAAGC,kBAAiB,EAAGC,cAAa,EAAGC,gBAAe,EAAG,GAAGC,MAAM,GAAGnB;IAChP,MAAMoB,UAAUC,IAAAA,qBAAK,EAAC;IACtB,MAAMC,SAASD,IAAAA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QACAI;QACAF;QACAyD;QACAtD;QACA+F,SAAS/E;QACTT;QACAM;QACAE;IACJ;AACJ"}
@@ -9,11 +9,11 @@ function _export(target, all) {
9
9
  });
10
10
  }
11
11
  _export(exports, {
12
- toastClassNames: ()=>toastClassNames,
12
+ toastContainerClassNames: ()=>toastContainerClassNames,
13
13
  useToastContainerStyles_unstable: ()=>useToastContainerStyles_unstable
14
14
  });
15
15
  const _react = require("@griffel/react");
16
- const toastClassNames = {
16
+ const toastContainerClassNames = {
17
17
  root: 'fui-ToastContainer',
18
18
  timer: 'fui-ToastContainer__timer'
19
19
  };
@@ -59,6 +59,6 @@ const useRootBaseClassName = /*#__PURE__*/ (0, _react["__resetStyles"])("r1qaza6
59
59
  const useToastContainerStyles_unstable = (state)=>{
60
60
  const rootBaseClassName = useRootBaseClassName();
61
61
  const styles = useStyles();
62
- state.root.className = (0, _react.mergeClasses)(toastClassNames.root, rootBaseClassName, state.visible ? styles.enter : styles.exit, state.root.className);
62
+ state.root.className = (0, _react.mergeClasses)(toastContainerClassNames.root, rootBaseClassName, state.visible ? styles.enter : styles.exit, state.root.className);
63
63
  return state;
64
64
  }; //# sourceMappingURL=useToastContainerStyles.styles.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useToastContainerStyles.styles.js"],"sourcesContent":["import { __resetStyles, __styles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';\nexport const toastClassNames = {\n root: 'fui-ToastContainer',\n timer: 'fui-ToastContainer__timer'\n};\nconst useRootBaseClassName = /*#__PURE__*/__resetStyles(\"r1qaza64\", \"r1e6dlul\", [\".r1qaza64{box-sizing:border-box;margin-top:16px;min-height:44px;pointer-events:all;border-bottom-right-radius:var(--borderRadiusMedium);border-bottom-left-radius:var(--borderRadiusMedium);border-top-right-radius:var(--borderRadiusMedium);border-top-left-radius:var(--borderRadiusMedium);--fui-toast-height:44px;}\", \".r1qaza64[data-fui-focus-visible]{outline-width:var(--strokeWidthThick);outline-style:solid;outline-color:var(--colorStrokeFocus2);}\", \".r1e6dlul{box-sizing:border-box;margin-top:16px;min-height:44px;pointer-events:all;border-bottom-left-radius:var(--borderRadiusMedium);border-bottom-right-radius:var(--borderRadiusMedium);border-top-left-radius:var(--borderRadiusMedium);border-top-right-radius:var(--borderRadiusMedium);--fui-toast-height:44px;}\", \".r1e6dlul[data-fui-focus-visible]{outline-width:var(--strokeWidthThick);outline-style:solid;outline-color:var(--colorStrokeFocus2);}\"]);\n/**\n * Styles for the root slot\n */\nconst useStyles = /*#__PURE__*/__styles({\n enter: {\n vin17d: \"fayl5bc\",\n m1gqa9: \"f17oyct0\",\n Bv12yb3: \"fvv8lvk\"\n },\n exit: {\n vin17d: \"f1tk3cza\",\n m1gqa9: \"f1nx6yy9\",\n Bv12yb3: \"f9wuypy\"\n }\n}, {\n d: [\".fayl5bc{-webkit-animation-duration:200ms,400ms;animation-duration:200ms,400ms;}\", \".f17oyct0{-webkit-animation-delay:0ms,200ms;animation-delay:0ms,200ms;}\", \".fvv8lvk{-webkit-animation-name:f1rp83na,f5j8bii;animation-name:f1rp83na,f5j8bii;}\", \".f1tk3cza{-webkit-animation-duration:400ms,200ms;animation-duration:400ms,200ms;}\", \".f1nx6yy9{-webkit-animation-delay:0ms,400ms;animation-delay:0ms,400ms;}\", \".f9wuypy{-webkit-animation-name:fk0lfw7,f1n32sdh;animation-name:fk0lfw7,f1n32sdh;}\"],\n k: [\"@-webkit-keyframes f1rp83na{from{max-height:0;opacity:0;margin-top:0;}to{margin-top:16px;opacity:0;max-height:var(--fui-toast-height);}}\", \"@keyframes f1rp83na{from{max-height:0;opacity:0;margin-top:0;}to{margin-top:16px;opacity:0;max-height:var(--fui-toast-height);}}\", \"@-webkit-keyframes f5j8bii{from{opacity:0;}to{opacity:1;}}\", \"@keyframes f5j8bii{from{opacity:0;}to{opacity:1;}}\", \"@-webkit-keyframes fk0lfw7{from{opacity:1;}to{opacity:0;}}\", \"@keyframes fk0lfw7{from{opacity:1;}to{opacity:0;}}\", \"@-webkit-keyframes f1n32sdh{from{opacity:0;}to{opacity:0;margin-top:0;max-height:0;}}\", \"@keyframes f1n32sdh{from{opacity:0;}to{opacity:0;margin-top:0;max-height:0;}}\"]\n});\n/**\n * Apply styling to the ToastContainer slots based on the state\n */\nexport const useToastContainerStyles_unstable = state => {\n const rootBaseClassName = useRootBaseClassName();\n const styles = useStyles();\n state.root.className = mergeClasses(toastClassNames.root, rootBaseClassName, state.visible ? styles.enter : styles.exit, state.root.className);\n return state;\n};\n//# sourceMappingURL=useToastContainerStyles.styles.js.map"],"names":["toastClassNames","useToastContainerStyles_unstable","root","timer","useRootBaseClassName","__resetStyles","useStyles","__styles","enter","vin17d","m1gqa9","Bv12yb3","exit","d","k","state","rootBaseClassName","styles","className","mergeClasses","visible"],"mappings":";;;;;;;;;;;IAGaA,eAAe,MAAfA;IA0BAC,gCAAgC,MAAhCA;;uBA7BqD;AAG3D,MAAMD,kBAAkB;IAC7BE,MAAM;IACNC,OAAO;AACT;AACA,MAAMC,uBAAuB,WAAW,GAAEC,IAAAA,uBAAa,EAAC,YAAY,YAAY;IAAC;IAA4T;IAAwI;IAA4T;CAAuI;AACx9B;;CAEC,GACD,MAAMC,YAAY,WAAW,GAAEC,IAAAA,kBAAQ,EAAC;IACtCC,OAAO;QACLC,QAAQ;QACRC,QAAQ;QACRC,SAAS;IACX;IACAC,MAAM;QACJH,QAAQ;QACRC,QAAQ;QACRC,SAAS;IACX;AACF,GAAG;IACDE,GAAG;QAAC;QAAoF;QAA2E;QAAsF;QAAqF;QAA2E;KAAqF;IAC9eC,GAAG;QAAC;QAA4I;QAAoI;QAA8D;QAAsD;QAA8D;QAAsD;QAAyF;KAAgF;AACvqB;AAIO,MAAMb,mCAAmCc,CAAAA,QAAS;IACvD,MAAMC,oBAAoBZ;IAC1B,MAAMa,SAASX;IACfS,MAAMb,IAAI,CAACgB,SAAS,GAAGC,IAAAA,mBAAY,EAACnB,gBAAgBE,IAAI,EAAEc,mBAAmBD,MAAMK,OAAO,GAAGH,OAAOT,KAAK,GAAGS,OAAOL,IAAI,EAAEG,MAAMb,IAAI,CAACgB,SAAS;IAC7I,OAAOH;AACT,GACA,0DAA0D"}
1
+ {"version":3,"sources":["useToastContainerStyles.styles.js"],"sourcesContent":["import { __resetStyles, __styles, mergeClasses, shorthands } from '@griffel/react';\nimport { tokens } from '@fluentui/react-theme';\nimport { createCustomFocusIndicatorStyle } from '@fluentui/react-tabster';\nexport const toastContainerClassNames = {\n root: 'fui-ToastContainer',\n timer: 'fui-ToastContainer__timer'\n};\nconst useRootBaseClassName = /*#__PURE__*/__resetStyles(\"r1qaza64\", \"r1e6dlul\", [\".r1qaza64{box-sizing:border-box;margin-top:16px;min-height:44px;pointer-events:all;border-bottom-right-radius:var(--borderRadiusMedium);border-bottom-left-radius:var(--borderRadiusMedium);border-top-right-radius:var(--borderRadiusMedium);border-top-left-radius:var(--borderRadiusMedium);--fui-toast-height:44px;}\", \".r1qaza64[data-fui-focus-visible]{outline-width:var(--strokeWidthThick);outline-style:solid;outline-color:var(--colorStrokeFocus2);}\", \".r1e6dlul{box-sizing:border-box;margin-top:16px;min-height:44px;pointer-events:all;border-bottom-left-radius:var(--borderRadiusMedium);border-bottom-right-radius:var(--borderRadiusMedium);border-top-left-radius:var(--borderRadiusMedium);border-top-right-radius:var(--borderRadiusMedium);--fui-toast-height:44px;}\", \".r1e6dlul[data-fui-focus-visible]{outline-width:var(--strokeWidthThick);outline-style:solid;outline-color:var(--colorStrokeFocus2);}\"]);\n/**\n * Styles for the root slot\n */\nconst useStyles = /*#__PURE__*/__styles({\n enter: {\n vin17d: \"fayl5bc\",\n m1gqa9: \"f17oyct0\",\n Bv12yb3: \"fvv8lvk\"\n },\n exit: {\n vin17d: \"f1tk3cza\",\n m1gqa9: \"f1nx6yy9\",\n Bv12yb3: \"f9wuypy\"\n }\n}, {\n d: [\".fayl5bc{-webkit-animation-duration:200ms,400ms;animation-duration:200ms,400ms;}\", \".f17oyct0{-webkit-animation-delay:0ms,200ms;animation-delay:0ms,200ms;}\", \".fvv8lvk{-webkit-animation-name:f1rp83na,f5j8bii;animation-name:f1rp83na,f5j8bii;}\", \".f1tk3cza{-webkit-animation-duration:400ms,200ms;animation-duration:400ms,200ms;}\", \".f1nx6yy9{-webkit-animation-delay:0ms,400ms;animation-delay:0ms,400ms;}\", \".f9wuypy{-webkit-animation-name:fk0lfw7,f1n32sdh;animation-name:fk0lfw7,f1n32sdh;}\"],\n k: [\"@-webkit-keyframes f1rp83na{from{max-height:0;opacity:0;margin-top:0;}to{margin-top:16px;opacity:0;max-height:var(--fui-toast-height);}}\", \"@keyframes f1rp83na{from{max-height:0;opacity:0;margin-top:0;}to{margin-top:16px;opacity:0;max-height:var(--fui-toast-height);}}\", \"@-webkit-keyframes f5j8bii{from{opacity:0;}to{opacity:1;}}\", \"@keyframes f5j8bii{from{opacity:0;}to{opacity:1;}}\", \"@-webkit-keyframes fk0lfw7{from{opacity:1;}to{opacity:0;}}\", \"@keyframes fk0lfw7{from{opacity:1;}to{opacity:0;}}\", \"@-webkit-keyframes f1n32sdh{from{opacity:0;}to{opacity:0;margin-top:0;max-height:0;}}\", \"@keyframes f1n32sdh{from{opacity:0;}to{opacity:0;margin-top:0;max-height:0;}}\"]\n});\n/**\n * Apply styling to the ToastContainer slots based on the state\n */\nexport const useToastContainerStyles_unstable = state => {\n const rootBaseClassName = useRootBaseClassName();\n const styles = useStyles();\n state.root.className = mergeClasses(toastContainerClassNames.root, rootBaseClassName, state.visible ? styles.enter : styles.exit, state.root.className);\n return state;\n};\n//# sourceMappingURL=useToastContainerStyles.styles.js.map"],"names":["toastContainerClassNames","useToastContainerStyles_unstable","root","timer","useRootBaseClassName","__resetStyles","useStyles","__styles","enter","vin17d","m1gqa9","Bv12yb3","exit","d","k","state","rootBaseClassName","styles","className","mergeClasses","visible"],"mappings":";;;;;;;;;;;IAGaA,wBAAwB,MAAxBA;IA0BAC,gCAAgC,MAAhCA;;uBA7BqD;AAG3D,MAAMD,2BAA2B;IACtCE,MAAM;IACNC,OAAO;AACT;AACA,MAAMC,uBAAuB,WAAW,GAAEC,IAAAA,uBAAa,EAAC,YAAY,YAAY;IAAC;IAA4T;IAAwI;IAA4T;CAAuI;AACx9B;;CAEC,GACD,MAAMC,YAAY,WAAW,GAAEC,IAAAA,kBAAQ,EAAC;IACtCC,OAAO;QACLC,QAAQ;QACRC,QAAQ;QACRC,SAAS;IACX;IACAC,MAAM;QACJH,QAAQ;QACRC,QAAQ;QACRC,SAAS;IACX;AACF,GAAG;IACDE,GAAG;QAAC;QAAoF;QAA2E;QAAsF;QAAqF;QAA2E;KAAqF;IAC9eC,GAAG;QAAC;QAA4I;QAAoI;QAA8D;QAAsD;QAA8D;QAAsD;QAAyF;KAAgF;AACvqB;AAIO,MAAMb,mCAAmCc,CAAAA,QAAS;IACvD,MAAMC,oBAAoBZ;IAC1B,MAAMa,SAASX;IACfS,MAAMb,IAAI,CAACgB,SAAS,GAAGC,IAAAA,mBAAY,EAACnB,yBAAyBE,IAAI,EAAEc,mBAAmBD,MAAMK,OAAO,GAAGH,OAAOT,KAAK,GAAGS,OAAOL,IAAI,EAAEG,MAAMb,IAAI,CAACgB,SAAS;IACtJ,OAAOH;AACT,GACA,0DAA0D"}
@@ -0,0 +1,50 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useToastAnnounce", {
6
+ enumerable: true,
7
+ get: ()=>useToastAnnounce
8
+ });
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
+ const _reactUtilities = require("@fluentui/react-utilities");
12
+ function useToastAnnounce(announce) {
13
+ const activeRef = _react.useRef(true);
14
+ const cleanupRef = _react.useRef(()=>undefined);
15
+ const announceToast = _react.useCallback((message, options)=>{
16
+ if (activeRef.current) {
17
+ announce(message, options);
18
+ }
19
+ }, [
20
+ announce
21
+ ]);
22
+ const toasterRef = _react.useCallback((el)=>{
23
+ if (!el) {
24
+ cleanupRef.current();
25
+ return;
26
+ }
27
+ const onFocusIn = (e)=>{
28
+ if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
29
+ return;
30
+ }
31
+ activeRef.current = false;
32
+ };
33
+ const onFocusOut = (e)=>{
34
+ if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
35
+ return;
36
+ }
37
+ activeRef.current = true;
38
+ };
39
+ el.addEventListener('focusin', onFocusIn);
40
+ el.addEventListener('focusout', onFocusOut);
41
+ cleanupRef.current = ()=>{
42
+ el.removeEventListener('focusin', onFocusIn);
43
+ el.removeEventListener('focusout', onFocusOut);
44
+ };
45
+ }, []);
46
+ return {
47
+ announceToast,
48
+ toasterRef
49
+ };
50
+ }
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useToastAnnounce.js"],"sourcesContent":["import * as React from 'react';\nimport { isHTMLElement } from '@fluentui/react-utilities';\n/**\n * Wraps an aria live announcement function.\n * Aria live announcements can be detrimental once the user is already navigating\n * multiple toasts. Once the user is focused inside the toaster, the announecments should be disabled.\n * @param announce\n * @returns A function to announce a toast and a ref to attach to the toaster element\n */ export function useToastAnnounce(announce) {\n const activeRef = React.useRef(true);\n const cleanupRef = React.useRef(()=>undefined);\n const announceToast = React.useCallback((message, options)=>{\n if (activeRef.current) {\n announce(message, options);\n }\n }, [\n announce\n ]);\n const toasterRef = React.useCallback((el)=>{\n if (!el) {\n cleanupRef.current();\n return;\n }\n const onFocusIn = (e)=>{\n if (isHTMLElement(e.currentTarget) && e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n return;\n }\n activeRef.current = false;\n };\n const onFocusOut = (e)=>{\n if (isHTMLElement(e.currentTarget) && e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n return;\n }\n activeRef.current = true;\n };\n el.addEventListener('focusin', onFocusIn);\n el.addEventListener('focusout', onFocusOut);\n cleanupRef.current = ()=>{\n el.removeEventListener('focusin', onFocusIn);\n el.removeEventListener('focusout', onFocusOut);\n };\n }, []);\n return {\n announceToast,\n toasterRef\n };\n}\n"],"names":["useToastAnnounce","announce","activeRef","React","useRef","cleanupRef","undefined","announceToast","useCallback","message","options","current","toasterRef","el","onFocusIn","e","isHTMLElement","currentTarget","contains","relatedTarget","onFocusOut","addEventListener","removeEventListener"],"mappings":";;;;+BAQoBA;;aAAAA;;;6DARG;gCACO;AAOnB,SAASA,iBAAiBC,QAAQ,EAAE;IAC3C,MAAMC,YAAYC,OAAMC,MAAM,CAAC,IAAI;IACnC,MAAMC,aAAaF,OAAMC,MAAM,CAAC,IAAIE;IACpC,MAAMC,gBAAgBJ,OAAMK,WAAW,CAAC,CAACC,SAASC,UAAU;QACxD,IAAIR,UAAUS,OAAO,EAAE;YACnBV,SAASQ,SAASC;QACtB,CAAC;IACL,GAAG;QACCT;KACH;IACD,MAAMW,aAAaT,OAAMK,WAAW,CAAC,CAACK,KAAK;QACvC,IAAI,CAACA,IAAI;YACLR,WAAWM,OAAO;YAClB;QACJ,CAAC;QACD,MAAMG,YAAY,CAACC,IAAI;YACnB,IAAIC,IAAAA,6BAAa,EAACD,EAAEE,aAAa,KAAKF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAa,EAACD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,IAAI,GAAG;gBACrH;YACJ,CAAC;YACDjB,UAAUS,OAAO,GAAG,KAAK;QAC7B;QACA,MAAMS,aAAa,CAACL,IAAI;YACpB,IAAIC,IAAAA,6BAAa,EAACD,EAAEE,aAAa,KAAKF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAa,EAACD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,IAAI,GAAG;gBACrH;YACJ,CAAC;YACDjB,UAAUS,OAAO,GAAG,IAAI;QAC5B;QACAE,GAAGQ,gBAAgB,CAAC,WAAWP;QAC/BD,GAAGQ,gBAAgB,CAAC,YAAYD;QAChCf,WAAWM,OAAO,GAAG,IAAI;YACrBE,GAAGS,mBAAmB,CAAC,WAAWR;YAClCD,GAAGS,mBAAmB,CAAC,YAAYF;QACvC;IACJ,GAAG,EAAE;IACL,OAAO;QACHb;QACAK;IACJ;AACJ"}
@@ -10,50 +10,52 @@ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildc
10
10
  const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
11
11
  const _reactUtilities = require("@fluentui/react-utilities");
12
12
  const _reactSharedContexts = require("@fluentui/react-shared-contexts");
13
+ const _reactTabster = require("@fluentui/react-tabster");
14
+ const _keyboardKeys = require("@fluentui/keyboard-keys");
13
15
  const _state = require("../../state");
14
16
  const _toastContainer = require("../ToastContainer");
17
+ const _useToasterFocusManagement = require("./useToasterFocusManagement");
18
+ const _useToastAnnounce = require("./useToastAnnounce");
15
19
  const useToaster_unstable = (props)=>{
16
20
  const { offset , announce: announceProp , ...rest } = props;
17
21
  const announceRef = _react.useRef(()=>null);
18
- const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus } = (0, _state.useToaster)(rest);
22
+ const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus , closeAllToasts } = (0, _state.useToaster)(rest);
19
23
  const announce = _react.useCallback((message, options)=>announceRef.current(message, options), []);
20
24
  const { dir } = (0, _reactSharedContexts.useFluent_unstable)();
21
25
  const rootProps = (0, _reactUtilities.getNativeElementProps)('div', rest);
22
- // Adds native HTML focusin/focusout listeners
23
- // https://github.com/facebook/react/issues/25194
24
- const focusListenerRef = _react.useCallback((el)=>{
25
- if (el) {
26
- el.addEventListener('focusin', (e)=>{
27
- if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
28
- pauseAllToasts();
29
- }
30
- });
31
- el.addEventListener('focusout', (e)=>{
32
- if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
33
- playAllToasts();
34
- tryRestoreFocus();
35
- }
36
- });
26
+ const focusableGroupAttr = (0, _reactTabster.useFocusableGroup)({
27
+ tabBehavior: 'limited-trap-focus',
28
+ ignoreDefaultKeydown: {
29
+ Escape: true
37
30
  }
38
- }, [
39
- playAllToasts,
40
- pauseAllToasts,
41
- tryRestoreFocus
42
- ]);
43
- const createPositionSlot = (toastPosition)=>{
31
+ });
32
+ const onKeyDown = (0, _reactUtilities.useEventCallback)((e)=>{
33
+ var _props_onKeyDown;
34
+ if (e.key === _keyboardKeys.Escape) {
35
+ e.preventDefault();
36
+ closeAllToasts();
37
+ }
38
+ (_props_onKeyDown = props.onKeyDown) === null || _props_onKeyDown === void 0 ? void 0 : _props_onKeyDown.call(props, e);
39
+ });
40
+ const usePositionSlot = (toastPosition)=>{
44
41
  var _toastsToRender_get;
42
+ const focusManagementRef = (0, _useToasterFocusManagement.useToasterFocusManagement_unstable)(pauseAllToasts, playAllToasts);
43
+ const { announceToast , toasterRef } = (0, _useToastAnnounce.useToastAnnounce)(announceProp !== null && announceProp !== void 0 ? announceProp : announce);
45
44
  return (0, _reactUtilities.resolveShorthand)(toastsToRender.has(toastPosition) ? rootProps : null, {
46
45
  defaultProps: {
47
- ref: focusListenerRef,
46
+ ref: (0, _reactUtilities.useMergedRefs)(focusManagementRef, toasterRef),
48
47
  children: (_toastsToRender_get = toastsToRender.get(toastPosition)) === null || _toastsToRender_get === void 0 ? void 0 : _toastsToRender_get.map((toast)=>/*#__PURE__*/ _react.createElement(_toastContainer.ToastContainer, {
49
48
  ...toast,
50
49
  tryRestoreFocus: tryRestoreFocus,
51
50
  intent: toast.intent,
52
- announce: announce,
51
+ announce: announceToast,
53
52
  key: toast.toastId,
54
53
  visible: isToastVisible(toast.toastId)
55
54
  }, toast.content)),
56
- 'data-toaster-position': toastPosition
55
+ onKeyDown,
56
+ ...focusableGroupAttr,
57
+ 'data-toaster-position': toastPosition,
58
+ role: 'list'
57
59
  }
58
60
  });
59
61
  };
@@ -69,10 +71,10 @@ const useToaster_unstable = (props)=>{
69
71
  root: (0, _reactUtilities.resolveShorthand)(rootProps, {
70
72
  required: true
71
73
  }),
72
- bottomStart: createPositionSlot(_state.TOAST_POSITIONS.bottomStart),
73
- bottomEnd: createPositionSlot(_state.TOAST_POSITIONS.bottomEnd),
74
- topStart: createPositionSlot(_state.TOAST_POSITIONS.topStart),
75
- topEnd: createPositionSlot(_state.TOAST_POSITIONS.topEnd),
74
+ bottomStart: usePositionSlot(_state.TOAST_POSITIONS.bottomStart),
75
+ bottomEnd: usePositionSlot(_state.TOAST_POSITIONS.bottomEnd),
76
+ topStart: usePositionSlot(_state.TOAST_POSITIONS.topStart),
77
+ topEnd: usePositionSlot(_state.TOAST_POSITIONS.topEnd),
76
78
  announceRef,
77
79
  offset,
78
80
  announce: announceProp !== null && announceProp !== void 0 ? announceProp : announce,
@@ -1 +1 @@
1
- {"version":3,"sources":["useToaster.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, isHTMLElement, resolveShorthand } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { TOAST_POSITIONS, useToaster } from '../../state';\nimport { ToastContainer } from '../ToastContainer';\n/**\n * Create the state required to render Toaster.\n *\n * @param props - props from this instance of Toaster\n */ export const useToaster_unstable = (props)=>{\n const { offset , announce: announceProp , ...rest } = props;\n const announceRef = React.useRef(()=>null);\n const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus } = useToaster(rest);\n const announce = React.useCallback((message, options)=>announceRef.current(message, options), []);\n const { dir } = useFluent();\n const rootProps = getNativeElementProps('div', rest);\n // Adds native HTML focusin/focusout listeners\n // https://github.com/facebook/react/issues/25194\n const focusListenerRef = React.useCallback((el)=>{\n if (el) {\n el.addEventListener('focusin', (e)=>{\n if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n pauseAllToasts();\n }\n });\n el.addEventListener('focusout', (e)=>{\n if (isHTMLElement(e.currentTarget) && !e.currentTarget.contains(isHTMLElement(e.relatedTarget) ? e.relatedTarget : null)) {\n playAllToasts();\n tryRestoreFocus();\n }\n });\n }\n }, [\n playAllToasts,\n pauseAllToasts,\n tryRestoreFocus\n ]);\n const createPositionSlot = (toastPosition)=>{\n var _toastsToRender_get;\n return resolveShorthand(toastsToRender.has(toastPosition) ? rootProps : null, {\n defaultProps: {\n ref: focusListenerRef,\n children: (_toastsToRender_get = toastsToRender.get(toastPosition)) === null || _toastsToRender_get === void 0 ? void 0 : _toastsToRender_get.map((toast)=>/*#__PURE__*/ React.createElement(ToastContainer, {\n ...toast,\n tryRestoreFocus: tryRestoreFocus,\n intent: toast.intent,\n announce: announce,\n key: toast.toastId,\n visible: isToastVisible(toast.toastId)\n }, toast.content)),\n 'data-toaster-position': toastPosition\n }\n });\n };\n return {\n dir,\n components: {\n root: 'div',\n bottomStart: 'div',\n bottomEnd: 'div',\n topStart: 'div',\n topEnd: 'div'\n },\n root: resolveShorthand(rootProps, {\n required: true\n }),\n bottomStart: createPositionSlot(TOAST_POSITIONS.bottomStart),\n bottomEnd: createPositionSlot(TOAST_POSITIONS.bottomEnd),\n topStart: createPositionSlot(TOAST_POSITIONS.topStart),\n topEnd: createPositionSlot(TOAST_POSITIONS.topEnd),\n announceRef,\n offset,\n announce: announceProp !== null && announceProp !== void 0 ? announceProp : announce,\n renderAriaLive: !announceProp\n };\n};\n"],"names":["useToaster_unstable","props","offset","announce","announceProp","rest","announceRef","React","useRef","toastsToRender","isToastVisible","pauseAllToasts","playAllToasts","tryRestoreFocus","useToaster","useCallback","message","options","current","dir","useFluent","rootProps","getNativeElementProps","focusListenerRef","el","addEventListener","e","isHTMLElement","currentTarget","contains","relatedTarget","createPositionSlot","toastPosition","_toastsToRender_get","resolveShorthand","has","defaultProps","ref","children","get","map","toast","createElement","ToastContainer","intent","key","toastId","visible","content","components","root","bottomStart","bottomEnd","topStart","topEnd","required","TOAST_POSITIONS","renderAriaLive"],"mappings":";;;;+BASiBA;;aAAAA;;;6DATM;gCACgD;qCACvB;uBACJ;gCACb;AAKpB,MAAMA,sBAAsB,CAACC,QAAQ;IAC5C,MAAM,EAAEC,OAAM,EAAGC,UAAUC,aAAY,EAAG,GAAGC,MAAM,GAAGJ;IACtD,MAAMK,cAAcC,OAAMC,MAAM,CAAC,IAAI,IAAI;IACzC,MAAM,EAAEC,eAAc,EAAGC,eAAc,EAAGC,eAAc,EAAGC,cAAa,EAAGC,gBAAe,EAAG,GAAGC,IAAAA,iBAAU,EAACT;IAC3G,MAAMF,WAAWI,OAAMQ,WAAW,CAAC,CAACC,SAASC,UAAUX,YAAYY,OAAO,CAACF,SAASC,UAAU,EAAE;IAChG,MAAM,EAAEE,IAAG,EAAG,GAAGC,IAAAA,uCAAS;IAC1B,MAAMC,YAAYC,IAAAA,qCAAqB,EAAC,OAAOjB;IAC/C,8CAA8C;IAC9C,iDAAiD;IACjD,MAAMkB,mBAAmBhB,OAAMQ,WAAW,CAAC,CAACS,KAAK;QAC7C,IAAIA,IAAI;YACJA,GAAGC,gBAAgB,CAAC,WAAW,CAACC,IAAI;gBAChC,IAAIC,IAAAA,6BAAa,EAACD,EAAEE,aAAa,KAAK,CAACF,EAAEE,aAAa,CAACC,QAAQ,CAACF,IAAAA,6BAAa,EAACD,EAAEI,aAAa,IAAIJ,EAAEI,aAAa,GAAG,IAAI,GAAG;oBACtHnB;gBACJ,CAAC;YACL;YACAa,GAAGC,gBAAgB,CAAC,YAAY,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IAAI,IAAIA,iBAAiB,KAAK,IAAIA,eAAeD,QAAQ;QACpFsD,gBAAgB,CAACrD;IACrB;AACJ"}
1
+ {"version":3,"sources":["useToaster.js"],"sourcesContent":["import * as React from 'react';\nimport { getNativeElementProps, resolveShorthand, useEventCallback, useMergedRefs } from '@fluentui/react-utilities';\nimport { useFluent_unstable as useFluent } from '@fluentui/react-shared-contexts';\nimport { useFocusableGroup } from '@fluentui/react-tabster';\nimport { Escape } from '@fluentui/keyboard-keys';\nimport { TOAST_POSITIONS, useToaster } from '../../state';\nimport { ToastContainer } from '../ToastContainer';\nimport { useToasterFocusManagement_unstable } from './useToasterFocusManagement';\nimport { useToastAnnounce } from './useToastAnnounce';\n/**\n * Create the state required to render Toaster.\n *\n * @param props - props from this instance of Toaster\n */ export const useToaster_unstable = (props)=>{\n const { offset , announce: announceProp , ...rest } = props;\n const announceRef = React.useRef(()=>null);\n const { toastsToRender , isToastVisible , pauseAllToasts , playAllToasts , tryRestoreFocus , closeAllToasts } = useToaster(rest);\n const announce = React.useCallback((message, options)=>announceRef.current(message, options), []);\n const { dir } = useFluent();\n const rootProps = getNativeElementProps('div', rest);\n const focusableGroupAttr = useFocusableGroup({\n tabBehavior: 'limited-trap-focus',\n ignoreDefaultKeydown: {\n Escape: true\n }\n });\n const onKeyDown = useEventCallback((e)=>{\n var _props_onKeyDown;\n if (e.key === Escape) {\n e.preventDefault();\n closeAllToasts();\n }\n (_props_onKeyDown = props.onKeyDown) === null || _props_onKeyDown === void 0 ? void 0 : _props_onKeyDown.call(props, e);\n });\n const usePositionSlot = (toastPosition)=>{\n var _toastsToRender_get;\n const focusManagementRef = useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts);\n const { announceToast , toasterRef } = useToastAnnounce(announceProp !== null && announceProp !== void 0 ? announceProp : announce);\n return resolveShorthand(toastsToRender.has(toastPosition) ? rootProps : null, {\n defaultProps: {\n ref: useMergedRefs(focusManagementRef, toasterRef),\n children: (_toastsToRender_get = toastsToRender.get(toastPosition)) === null || _toastsToRender_get === void 0 ? void 0 : _toastsToRender_get.map((toast)=>/*#__PURE__*/ React.createElement(ToastContainer, {\n ...toast,\n tryRestoreFocus: tryRestoreFocus,\n intent: toast.intent,\n announce: announceToast,\n key: toast.toastId,\n visible: isToastVisible(toast.toastId)\n }, toast.content)),\n onKeyDown,\n ...focusableGroupAttr,\n 'data-toaster-position': toastPosition,\n role: 'list'\n }\n });\n };\n return {\n dir,\n components: {\n root: 'div',\n bottomStart: 'div',\n bottomEnd: 'div',\n topStart: 'div',\n topEnd: 'div'\n },\n root: resolveShorthand(rootProps, {\n required: true\n }),\n bottomStart: usePositionSlot(TOAST_POSITIONS.bottomStart),\n bottomEnd: usePositionSlot(TOAST_POSITIONS.bottomEnd),\n topStart: usePositionSlot(TOAST_POSITIONS.topStart),\n topEnd: usePositionSlot(TOAST_POSITIONS.topEnd),\n announceRef,\n offset,\n announce: announceProp !== null && announceProp !== void 0 ? announceProp : announce,\n renderAriaLive: !announceProp\n };\n};\n"],"names":["useToaster_unstable","props","offset","announce","announceProp","rest","announceRef","React","useRef","toastsToRender","isToastVisible","pauseAllToasts","playAllToasts","tryRestoreFocus","closeAllToasts","useToaster","useCallback","message","options","current","dir","useFluent","rootProps","getNativeElementProps","focusableGroupAttr","useFocusableGroup","tabBehavior","ignoreDefaultKeydown","Escape","onKeyDown","useEventCallback","e","_props_onKeyDown","key","preventDefault","call","usePositionSlot","toastPosition","_toastsToRender_get","focusManagementRef","useToasterFocusManagement_unstable","announceToast","toasterRef","useToastAnnounce","resolveShorthand","has","defaultProps","ref","useMergedRefs","children","get","map","toast","createElement","ToastContainer","intent","toastId","visible","content","role","components","root","bottomStart","bottomEnd","topStart","topEnd","required","TOAST_POSITIONS","renderAriaLive"],"mappings":";;;;+BAaiBA;;aAAAA;;;6DAbM;gCACkE;qCACzC;8BACd;8BACX;uBACqB;gCACb;2CACoB;kCAClB;AAKtB,MAAMA,sBAAsB,CAACC,QAAQ;IAC5C,MAAM,EAA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CO,UAAU,AAACX,CAAAA,sBAAsB7B,eAAeyC,GAAG,CAACb,cAAa,MAAO,IAAI,IAAIC,wBAAwB,KAAK,IAAI,KAAK,IAAIA,oBAAoBa,GAAG,CAAC,CAACC,QAAQ,WAAW,GAAG7C,OAAM8C,aAAa,CAACC,8BAAc,EAAE;wBACrM,GAAGF,KAAK;wBACRvC,iBAAiBA;wBACjB0C,QAAQH,MAAMG,MAAM;wBACpBpD,UAAUsC;wBACVR,KAAKmB,MAAMI,OAAO;wBAClBC,SAAS/C,eAAe0C,MAAMI,OAAO;oBACzC,GAAGJ,MAAMM,OAAO,EAAE;gBACtB7B;gBACA,GAAGL,kBAAkB;gBACrB,yBAAyBa;gBACzBsB,MAAM;YACV;QACJ;IACJ;IACA,OAAO;QACHvC;QACAwC,YAAY;YACRC,MAAM;YACNC,aAAa;YACbC,WAAW;YACXC,UAAU;YACVC,QAAQ;QACZ;QACAJ,MAAMjB,IAAAA,gCAAgB,EAACtB,WAAW;YAC9B4C,UAAU,IAAI;QAClB;QACAJ,aAAa1B,gBAAgB+B,sBAAe,CAACL,WAAW;QACxDC,WAAW3B,gBAAgB+B,sBAAe,CAACJ,SAAS;QACpDC,UAAU5B,gBAAgB+B,sBAAe,CAACH,QAAQ;QAClDC,QAAQ7B,gBAAgB+B,sBAAe,CAACF,MAAM;QAC9C3D;QACAJ;QACAC,UAAUC,iBAAiB,IAAI,IAAIA,iBAAiB,KAAK,IAAIA,eAAeD,QAAQ;QACpFiE,gBAAgB,CAAChE;IACrB;AACJ"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "useToasterFocusManagement_unstable", {
6
+ enumerable: true,
7
+ get: ()=>useToasterFocusManagement_unstable
8
+ });
9
+ const _interopRequireWildcard = require("@swc/helpers/lib/_interop_require_wildcard.js").default;
10
+ const _reactUtilities = require("@fluentui/react-utilities");
11
+ const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
12
+ const _reactSharedContexts = require("@fluentui/react-shared-contexts");
13
+ const _keyboardKeys = require("@fluentui/keyboard-keys");
14
+ const _toastContainer = require("../ToastContainer");
15
+ const noop = ()=>undefined;
16
+ function useToasterFocusManagement_unstable(pauseAllToasts, playAllToasts) {
17
+ const { targetDocument } = (0, _reactSharedContexts.useFluent_unstable)();
18
+ const cleanupListenersRef = _react.useRef(noop);
19
+ return _react.useCallback((el)=>{
20
+ if (!el || !targetDocument) {
21
+ cleanupListenersRef.current();
22
+ cleanupListenersRef.current = noop;
23
+ return;
24
+ }
25
+ const toastContainerWalker = targetDocument.createTreeWalker(el, NodeFilter.SHOW_ELEMENT, {
26
+ acceptNode (node) {
27
+ if ((0, _reactUtilities.isHTMLElement)(node) && node.classList.contains(_toastContainer.toastContainerClassNames.root)) {
28
+ return NodeFilter.FILTER_ACCEPT;
29
+ }
30
+ return NodeFilter.FILTER_SKIP;
31
+ }
32
+ });
33
+ /**
34
+ * FIXME: https://github.com/microsoft/tabster/issues/299
35
+ * Toasts should be arrow navigable and focus should be trapped in a stack of tasts
36
+ * This is a temporary measure, Tabster does not have an API yet to enable mover arrow keys from within grouppers
37
+ * Once tabster fully supports this use case, remove this hook
38
+ */ const keydownListener = (e)=>{
39
+ const { target , key } = e;
40
+ if (!(0, _reactUtilities.isHTMLElement)(target)) {
41
+ return;
42
+ }
43
+ if (key === _keyboardKeys.ArrowDown) {
44
+ toastContainerWalker.currentNode = target;
45
+ let nextToastContainer = toastContainerWalker.nextNode();
46
+ if (!nextToastContainer) {
47
+ toastContainerWalker.currentNode = el;
48
+ nextToastContainer = toastContainerWalker.nextNode();
49
+ }
50
+ if ((0, _reactUtilities.isHTMLElement)(nextToastContainer)) {
51
+ nextToastContainer.focus();
52
+ }
53
+ }
54
+ if (key === _keyboardKeys.ArrowUp) {
55
+ toastContainerWalker.currentNode = target;
56
+ let prevToastContainer = toastContainerWalker.previousNode();
57
+ if (prevToastContainer && prevToastContainer.contains(target)) {
58
+ prevToastContainer = toastContainerWalker.previousNode();
59
+ }
60
+ if (!prevToastContainer) {
61
+ toastContainerWalker.currentNode = el;
62
+ prevToastContainer = toastContainerWalker.lastChild();
63
+ }
64
+ if ((0, _reactUtilities.isHTMLElement)(prevToastContainer)) {
65
+ prevToastContainer.focus();
66
+ }
67
+ }
68
+ };
69
+ const focusInListener = (e)=>{
70
+ if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
71
+ pauseAllToasts();
72
+ }
73
+ };
74
+ const focusOutListener = (e)=>{
75
+ if ((0, _reactUtilities.isHTMLElement)(e.currentTarget) && !e.currentTarget.contains((0, _reactUtilities.isHTMLElement)(e.relatedTarget) ? e.relatedTarget : null)) {
76
+ playAllToasts();
77
+ }
78
+ };
79
+ el.addEventListener('keydown', keydownListener);
80
+ el.addEventListener('focusin', focusInListener);
81
+ el.addEventListener('focusout', focusOutListener);
82
+ cleanupListenersRef.current = ()=>{
83
+ el.removeEventListener('keydown', keydownListener);
84
+ el.removeEventListener('focusin', focusInListener);
85
+ el.removeEventListener('focusout', focusOutListener);
86
+ };
87
+ }, [
88
+ targetDocument,
89
+ pauseAllToasts,
90
+ playAllToasts
91
+ ]);
92
+ }