@react-aria/toast 3.0.9 → 3.0.11

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.
@@ -170,7 +170,7 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
170
170
  // listen to focus events separate from focuswithin because that will only fire once
171
171
  // and we need to follow all focus changes
172
172
  onFocus: (e)=>{
173
- let target = e.target.closest('[role="alertdialog"]');
173
+ let target = (0, $eO7VF$reactariautils.getEventTarget)(e).closest('[role="alertdialog"]');
174
174
  focusedToast.current = toasts.current.findIndex((t)=>t === target);
175
175
  },
176
176
  onBlur: ()=>{
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,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,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,mBAAK,EAAE;IACvB,IAAI,eAAe,CAAA,GAAA,wBAAU,EAAE;QAC7B,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,QAAQ;aAEd,MAAM,SAAS;IAEnB,GAAG;QAAC;KAAM;IAEV,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,qCAAO,EAAE;QAC1B,cAAc;YACZ,UAAU,OAAO,GAAG;YACpB;QACF;QACA,YAAY;YACV,UAAU,OAAO,GAAG;YACpB;QACF;IACF;IAEA,wCAAwC;IACxC,2HAA2H;IAC3H,I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AC/B,CAAA,GAAA,2CAAoB,EAAE,YAAY,OAAO;iBAEzC,YAAY,OAAO,CAAC,KAAK;YAE3B,YAAY,OAAO,GAAG;QACxB;IACF,GAAG;QAAC;QAAK,MAAM,aAAa,CAAC,MAAM;KAAC;IAEpC,CAAA,GAAA,sBAAQ,EAAE;QACR,OAAO;gBACD;YAAJ,KAAI,uBAAA,YAAY,OAAO,cAAnB,2CAAA,qBAAqB,WAAW,EAAE;gBACpC,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":["/*\n * Copyright 2025 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 {AriaLabelingProps, DOMAttributes, FocusableElement, 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 {useCallback, 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 isHovered = useRef(false);\n let isFocused = useRef(false);\n let updateTimers = useCallback(() => {\n if (isHovered.current || isFocused.current) {\n state.pauseAll();\n } else {\n state.resumeAll();\n }\n }, [state]);\n\n let {hoverProps} = useHover({\n onHoverStart: () => {\n isHovered.current = true;\n updateTimers();\n },\n onHoverEnd: () => {\n isHovered.current = false;\n updateTimers();\n }\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 let toasts = useRef<FocusableElement[]>([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef<number | null>(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0 || !ref.current) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')] as FocusableElement[];\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 && t.isRemoved);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n // In pointer modality, move focus out of the toast region.\n // Otherwise auto-dismiss timers will appear \"stuck\".\n if (getInteractionModality() === 'pointer' && lastFocused.current?.isConnected) {\n focusWithoutScrolling(lastFocused.current);\n } else {\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\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref]);\n\n let lastFocused = useRef<FocusableElement | null>(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n isFocused.current = true;\n lastFocused.current = e.relatedTarget as FocusableElement;\n updateTimers();\n },\n onBlurWithin: () => {\n isFocused.current = false;\n lastFocused.current = null;\n updateTimers();\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?.isConnected) {\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?.isConnected) {\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
+ {"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,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,MAA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,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":["/*\n * Copyright 2025 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 {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, getEventTarget, 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 {useCallback, 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 isHovered = useRef(false);\n let isFocused = useRef(false);\n let updateTimers = useCallback(() => {\n if (isHovered.current || isFocused.current) {\n state.pauseAll();\n } else {\n state.resumeAll();\n }\n }, [state]);\n\n let {hoverProps} = useHover({\n onHoverStart: () => {\n isHovered.current = true;\n updateTimers();\n },\n onHoverEnd: () => {\n isHovered.current = false;\n updateTimers();\n }\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 let toasts = useRef<FocusableElement[]>([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef<number | null>(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0 || !ref.current) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')] as FocusableElement[];\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 && t.isRemoved);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n // In pointer modality, move focus out of the toast region.\n // Otherwise auto-dismiss timers will appear \"stuck\".\n if (getInteractionModality() === 'pointer' && lastFocused.current?.isConnected) {\n focusWithoutScrolling(lastFocused.current);\n } else {\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\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref]);\n\n let lastFocused = useRef<FocusableElement | null>(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n isFocused.current = true;\n lastFocused.current = e.relatedTarget as FocusableElement;\n updateTimers();\n },\n onBlurWithin: () => {\n isFocused.current = false;\n lastFocused.current = null;\n updateTimers();\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?.isConnected) {\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?.isConnected) {\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 = (getEventTarget(e) as Element).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 {useLayoutEffect as $ckyCP$useLayoutEffect, 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, getEventTarget as $ckyCP$getEventTarget} from "@react-aria/utils";
3
3
  import {useHover as $ckyCP$useHover, getInteractionModality as $ckyCP$getInteractionModality, useFocusWithin as $ckyCP$useFocusWithin} from "@react-aria/interactions";
4
4
  import {useRef as $ckyCP$useRef, useCallback as $ckyCP$useCallback, useEffect as $ckyCP$useEffect} from "react";
5
5
  import {useLandmark as $ckyCP$useLandmark} from "@react-aria/landmark";
@@ -164,7 +164,7 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
164
164
  // listen to focus events separate from focuswithin because that will only fire once
165
165
  // and we need to follow all focus changes
166
166
  onFocus: (e)=>{
167
- let target = e.target.closest('[role="alertdialog"]');
167
+ let target = (0, $ckyCP$getEventTarget)(e).closest('[role="alertdialog"]');
168
168
  focusedToast.current = toasts.current.findIndex((t)=>t === target);
169
169
  },
170
170
  onBlur: ()=>{
@@ -1,5 +1,5 @@
1
1
  import $ckyCP$intlStringsmodulejs from "./intlStrings.module.js";
2
- import {useLayoutEffect as $ckyCP$useLayoutEffect, 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, getEventTarget as $ckyCP$getEventTarget} from "@react-aria/utils";
3
3
  import {useHover as $ckyCP$useHover, getInteractionModality as $ckyCP$getInteractionModality, useFocusWithin as $ckyCP$useFocusWithin} from "@react-aria/interactions";
4
4
  import {useRef as $ckyCP$useRef, useCallback as $ckyCP$useCallback, useEffect as $ckyCP$useEffect} from "react";
5
5
  import {useLandmark as $ckyCP$useLandmark} from "@react-aria/landmark";
@@ -164,7 +164,7 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
164
164
  // listen to focus events separate from focuswithin because that will only fire once
165
165
  // and we need to follow all focus changes
166
166
  onFocus: (e)=>{
167
- let target = e.target.closest('[role="alertdialog"]');
167
+ let target = (0, $ckyCP$getEventTarget)(e).closest('[role="alertdialog"]');
168
168
  focusedToast.current = toasts.current.findIndex((t)=>t === target);
169
169
  },
170
170
  onBlur: ()=>{
@@ -1 +1 @@
1
- {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,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,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,YAAY,CAAA,GAAA,aAAK,EAAE;IACvB,IAAI,eAAe,CAAA,GAAA,kBAAU,EAAE;QAC7B,IAAI,UAAU,OAAO,IAAI,UAAU,OAAO,EACxC,MAAM,QAAQ;aAEd,MAAM,SAAS;IAEnB,GAAG;QAAC;KAAM;IAEV,IAAI,cAAC,UAAU,EAAC,GAAG,CAAA,GAAA,eAAO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IAAI,MAAM,aAAa,CAAC,MAAM,KAAK,OAAK,uBAAA,YAAY,OAAO,cAAnB,2CAAA,qBAAqB,WAAW,GAAE;YACxE,IAAI,CAAA,GAAA,6BAAqB,QAAQ,WAC/B,CAAA,GAAA,4BAAoB,EAAE,YAAY,OAAO;iBAEzC,YAAY,OAAO,CAAC,KAAK;YAE3B,YAAY,OAAO,GAAG;QACxB;IACF,GAAG;QAAC;QAAK,MAAM,aAAa,CAAC,MAAM;KAAC;IAEpC,CAAA,GAAA,gBAAQ,EAAE;QACR,OAAO;gBACD;YAAJ,KAAI,uBAAA,YAAY,OAAO,cAAnB,2CAAA,qBAAqB,WAAW,EAAE;gBACpC,IAAI,CAAA,GAAA,6BAAqB,QAAQ,WAC/B,CAAA,GAAA,4BAAoB,EAAE,YAAY,OAAO;qBAEzC,YAAY,OAAO,CAAC,KAAK;gBAE3B,YAAY,OAAO,GAAG;YACxB;QACF;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;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":["/*\n * Copyright 2025 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 {AriaLabelingProps, DOMAttributes, FocusableElement, 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 {useCallback, 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 isHovered = useRef(false);\n let isFocused = useRef(false);\n let updateTimers = useCallback(() => {\n if (isHovered.current || isFocused.current) {\n state.pauseAll();\n } else {\n state.resumeAll();\n }\n }, [state]);\n\n let {hoverProps} = useHover({\n onHoverStart: () => {\n isHovered.current = true;\n updateTimers();\n },\n onHoverEnd: () => {\n isHovered.current = false;\n updateTimers();\n }\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 let toasts = useRef<FocusableElement[]>([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef<number | null>(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0 || !ref.current) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')] as FocusableElement[];\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 && t.isRemoved);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n // In pointer modality, move focus out of the toast region.\n // Otherwise auto-dismiss timers will appear \"stuck\".\n if (getInteractionModality() === 'pointer' && lastFocused.current?.isConnected) {\n focusWithoutScrolling(lastFocused.current);\n } else {\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\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref]);\n\n let lastFocused = useRef<FocusableElement | null>(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n isFocused.current = true;\n lastFocused.current = e.relatedTarget as FocusableElement;\n updateTimers();\n },\n onBlurWithin: () => {\n isFocused.current = false;\n lastFocused.current = null;\n updateTimers();\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?.isConnected) {\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?.isConnected) {\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
+ {"mappings":";;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;;;AA6BM,SAAS,0CAAkB,KAA2B,EAAE,KAAoB,EAAE,GAAkC;IACrH,IAAI,kBAAkB,CAAA,GAAA,kCAA0B,EAAE,CAAA,GAAA,oDAAW,GAAG;IAChE,IAAI,iBAAC,aAAa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F,0CAA0C;YAC1C,SAAS,CAAC;gBACR,IAAI,SAAS,AAAC,CAAA,GAAA,qBAAa,EAAE,GAAe,OAAO,CAAC;gBACpD,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":["/*\n * Copyright 2025 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 {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {focusWithoutScrolling, getEventTarget, 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 {useCallback, 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 isHovered = useRef(false);\n let isFocused = useRef(false);\n let updateTimers = useCallback(() => {\n if (isHovered.current || isFocused.current) {\n state.pauseAll();\n } else {\n state.resumeAll();\n }\n }, [state]);\n\n let {hoverProps} = useHover({\n onHoverStart: () => {\n isHovered.current = true;\n updateTimers();\n },\n onHoverEnd: () => {\n isHovered.current = false;\n updateTimers();\n }\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 let toasts = useRef<FocusableElement[]>([]);\n let prevVisibleToasts = useRef(state.visibleToasts);\n let focusedToast = useRef<number | null>(null);\n useLayoutEffect(() => {\n // If no toast has focus, then don't do anything.\n if (focusedToast.current === -1 || state.visibleToasts.length === 0 || !ref.current) {\n toasts.current = [];\n prevVisibleToasts.current = state.visibleToasts;\n return;\n }\n toasts.current = [...ref.current.querySelectorAll('[role=\"alertdialog\"]')] as FocusableElement[];\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 && t.isRemoved);\n\n // If the focused toast was removed, focus the next or previous toast.\n if (removedFocusedToastIndex > -1) {\n // In pointer modality, move focus out of the toast region.\n // Otherwise auto-dismiss timers will appear \"stuck\".\n if (getInteractionModality() === 'pointer' && lastFocused.current?.isConnected) {\n focusWithoutScrolling(lastFocused.current);\n } else {\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\n prevVisibleToasts.current = state.visibleToasts;\n }, [state.visibleToasts, ref]);\n\n let lastFocused = useRef<FocusableElement | null>(null);\n let {focusWithinProps} = useFocusWithin({\n onFocusWithin: (e) => {\n isFocused.current = true;\n lastFocused.current = e.relatedTarget as FocusableElement;\n updateTimers();\n },\n onBlurWithin: () => {\n isFocused.current = false;\n lastFocused.current = null;\n updateTimers();\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?.isConnected) {\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?.isConnected) {\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 = (getEventTarget(e) as Element).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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@react-aria/toast",
3
- "version": "3.0.9",
3
+ "version": "3.0.11",
4
4
  "description": "Spectrum UI components in React",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/main.js",
@@ -26,13 +26,13 @@
26
26
  "url": "https://github.com/adobe/react-spectrum"
27
27
  },
28
28
  "dependencies": {
29
- "@react-aria/i18n": "^3.12.14",
30
- "@react-aria/interactions": "^3.26.0",
31
- "@react-aria/landmark": "^3.0.8",
32
- "@react-aria/utils": "^3.32.0",
33
- "@react-stately/toast": "^3.1.2",
34
- "@react-types/button": "^3.14.1",
35
- "@react-types/shared": "^3.32.1",
29
+ "@react-aria/i18n": "^3.12.16",
30
+ "@react-aria/interactions": "^3.27.1",
31
+ "@react-aria/landmark": "^3.0.10",
32
+ "@react-aria/utils": "^3.33.1",
33
+ "@react-stately/toast": "^3.1.3",
34
+ "@react-types/button": "^3.15.1",
35
+ "@react-types/shared": "^3.33.1",
36
36
  "@swc/helpers": "^0.5.0"
37
37
  },
38
38
  "peerDependencies": {
@@ -42,5 +42,5 @@
42
42
  "publishConfig": {
43
43
  "access": "public"
44
44
  },
45
- "gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
45
+ "gitHead": "8df187370053aa35f553cb388ad670f65e1ab371"
46
46
  }
@@ -11,7 +11,7 @@
11
11
  */
12
12
 
13
13
  import {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
14
- import {focusWithoutScrolling, mergeProps, useLayoutEffect} from '@react-aria/utils';
14
+ import {focusWithoutScrolling, getEventTarget, mergeProps, useLayoutEffect} from '@react-aria/utils';
15
15
  import {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';
16
16
  // @ts-ignore
17
17
  import intlMessages from '../intl/*.json';
@@ -190,7 +190,7 @@ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState
190
190
  // listen to focus events separate from focuswithin because that will only fire once
191
191
  // and we need to follow all focus changes
192
192
  onFocus: (e) => {
193
- let target = e.target.closest('[role="alertdialog"]');
193
+ let target = (getEventTarget(e) as Element).closest('[role="alertdialog"]');
194
194
  focusedToast.current = toasts.current.findIndex(t => t === target);
195
195
  },
196
196
  onBlur: () => {