@react-aria/toast 3.0.8 → 3.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/useToast.main.js +1 -1
- package/dist/useToast.main.js.map +1 -1
- package/dist/useToast.mjs +2 -2
- package/dist/useToast.module.js +2 -2
- package/dist/useToast.module.js.map +1 -1
- package/dist/useToastRegion.main.js +5 -4
- package/dist/useToastRegion.main.js.map +1 -1
- package/dist/useToastRegion.mjs +7 -6
- package/dist/useToastRegion.module.js +7 -6
- package/dist/useToastRegion.module.js.map +1 -1
- package/package.json +6 -6
- package/src/useToast.ts +2 -2
- package/src/useToastRegion.ts +5 -5
package/dist/useToast.main.js
CHANGED
|
@@ -46,7 +46,7 @@ function $ec537504faac71d2$export$a407b657d3044108(props, state, ref) {
|
|
|
46
46
|
// Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5
|
|
47
47
|
// but toasts don't always have animations.
|
|
48
48
|
let [isVisible, setIsVisible] = (0, $ijFUR$react.useState)(false);
|
|
49
|
-
(0, $ijFUR$
|
|
49
|
+
(0, $ijFUR$reactariautils.useLayoutEffect)(()=>{
|
|
50
50
|
setIsVisible(true);
|
|
51
51
|
}, []);
|
|
52
52
|
let toastProps = (0, $ijFUR$reactariautils.filterDOMProps)(props, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;AAAA;;;;;;;;;;CAUC;;;;AAkCM,SAAS,0CAAY,KAAwB,EAAE,KAAoB,EAAE,GAAuC;IACjH,IAAI,OACF,GAAG,SACH,KAAK,WACL,OAAO,EACR,GAAG,MAAM,KAAK;IAEf,CAAA,GAAA,sBAAQ,EAAE;QACR,IAAI,SAAS,QAAQ,WAAW,MAC9B;QAGF,MAAM,KAAK,CAAC;QACZ,OAAO;YACL,MAAM,KAAK;QACb;IACF,GAAG;QAAC;QAAO;KAAQ;IAEnB,IAAI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AAY;YACV,IAAI;QACN;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,kBAAkB;YAChB,cAAc,gBAAgB,MAAM,CAAC;YACrC,SAAS,IAAM,MAAM,KAAK,CAAC;QAC7B;IACF;AACF","sources":["packages/@react-aria/toast/src/useToast.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {filterDOMProps, useId, useLayoutEffect, useSlotId} from '@react-aria/utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport {useEffect, useState} from 'react';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastProps<T> extends AriaLabelingProps {\n /** The toast object. */\n toast: QueuedToast<T>\n}\n\nexport interface ToastAria {\n /** Props for the toast container, non-modal dialog element. */\n toastProps: DOMAttributes,\n /** Props for the toast content alert message. */\n contentProps: DOMAttributes,\n /** Props for the toast title element. */\n titleProps: DOMAttributes,\n /** Props for the toast description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the toast close button. */\n closeButtonProps: AriaButtonProps\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast component.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement | null>): ToastAria {\n let {\n key,\n timer,\n timeout\n } = props.toast;\n\n useEffect(() => {\n if (timer == null || timeout == null) {\n return;\n }\n\n timer.reset(timeout);\n return () => {\n timer.pause();\n };\n }, [timer, timeout]);\n\n let titleId = useId();\n let descriptionId = useSlotId();\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n\n // This is required for NVDA announcements, without it NVDA will NOT announce the toast when it appears.\n // Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5\n // but toasts don't always have animations.\n let [isVisible, setIsVisible] = useState(false);\n useLayoutEffect(() => {\n setIsVisible(true);\n }, []);\n\n let toastProps = filterDOMProps(props, {labelable: true});\n\n return {\n toastProps: {\n ...toastProps,\n role: 'alertdialog',\n 'aria-modal': 'false',\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n 'aria-describedby': props['aria-describedby'] || descriptionId,\n tabIndex: 0\n },\n contentProps: {\n role: 'alert',\n 'aria-atomic': 'true',\n 'aria-hidden': isVisible ? undefined : 'true'\n },\n titleProps: {\n id: titleId\n },\n descriptionProps: {\n id: descriptionId\n },\n closeButtonProps: {\n 'aria-label': stringFormatter.format('close'),\n onPress: () => state.close(key)\n }\n };\n}\n"],"names":[],"version":3,"file":"useToast.main.js.map"}
|
package/dist/useToast.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $7WpW4$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
-
import {useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId, filterDOMProps as $7WpW4$filterDOMProps} from "@react-aria/utils";
|
|
2
|
+
import {useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId, useLayoutEffect as $7WpW4$useLayoutEffect, filterDOMProps as $7WpW4$filterDOMProps} from "@react-aria/utils";
|
|
3
3
|
import {useEffect as $7WpW4$useEffect, useState as $7WpW4$useState} from "react";
|
|
4
4
|
import {useLocalizedStringFormatter as $7WpW4$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
5
5
|
|
|
@@ -40,7 +40,7 @@ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
|
40
40
|
// Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5
|
|
41
41
|
// but toasts don't always have animations.
|
|
42
42
|
let [isVisible, setIsVisible] = (0, $7WpW4$useState)(false);
|
|
43
|
-
(0, $7WpW4$
|
|
43
|
+
(0, $7WpW4$useLayoutEffect)(()=>{
|
|
44
44
|
setIsVisible(true);
|
|
45
45
|
}, []);
|
|
46
46
|
let toastProps = (0, $7WpW4$filterDOMProps)(props, {
|
package/dist/useToast.module.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import $7WpW4$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
|
-
import {useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId, filterDOMProps as $7WpW4$filterDOMProps} from "@react-aria/utils";
|
|
2
|
+
import {useId as $7WpW4$useId, useSlotId as $7WpW4$useSlotId, useLayoutEffect as $7WpW4$useLayoutEffect, filterDOMProps as $7WpW4$filterDOMProps} from "@react-aria/utils";
|
|
3
3
|
import {useEffect as $7WpW4$useEffect, useState as $7WpW4$useState} from "react";
|
|
4
4
|
import {useLocalizedStringFormatter as $7WpW4$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
5
5
|
|
|
@@ -40,7 +40,7 @@ function $d6542812f0669241$export$a407b657d3044108(props, state, ref) {
|
|
|
40
40
|
// Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5
|
|
41
41
|
// but toasts don't always have animations.
|
|
42
42
|
let [isVisible, setIsVisible] = (0, $7WpW4$useState)(false);
|
|
43
|
-
(0, $7WpW4$
|
|
43
|
+
(0, $7WpW4$useLayoutEffect)(()=>{
|
|
44
44
|
setIsVisible(true);
|
|
45
45
|
}, []);
|
|
46
46
|
let toastProps = (0, $7WpW4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AAA,eAAO,EAAE;IACzC,CAAA,GAAA,sBAAc,EAAE;QACd,aAAa;IACf,GAAG,EAAE;IAEL,IAAI,aAAa,CAAA,GAAA,qBAAa,EAAE,OAAO;QAAC,WAAW;IAAI;IAEvD,OAAO;QACL,YAAY;YACV,GAAG,UAAU;YACb,MAAM;YACN,cAAc;YACd,mBAAmB,KAAK,CAAC,kBAAkB,IAAI;YAC/C,oBAAoB,KAAK,CAAC,mBAAmB,IAAI;YACjD,UAAU;QACZ;QACA,cAAc;YACZ,MAAM;YACN,eAAe;YACf,eAAe,YAAY,YAAY;QACzC;QACA,YAAY;YACV,IAAI;QACN;QACA,kBAAkB;YAChB,IAAI;QACN;QACA,kBAAkB;YAChB,cAAc,gBAAgB,MAAM,CAAC;YACrC,SAAS,IAAM,MAAM,KAAK,CAAC;QAC7B;IACF;AACF","sources":["packages/@react-aria/toast/src/useToast.ts"],"sourcesContent":["/*\n * Copyright 2020 Adobe. All rights reserved.\n * This file is licensed to you under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License. You may obtain a copy\n * of the License at http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software distributed under\n * the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS\n * OF ANY KIND, either express or implied. See the License for the specific language\n * governing permissions and limitations under the License.\n */\n\nimport {AriaButtonProps} from '@react-types/button';\nimport {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';\nimport {filterDOMProps, useId, useLayoutEffect, useSlotId} from '@react-aria/utils';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {QueuedToast, ToastState} from '@react-stately/toast';\nimport {useEffect, useState} from 'react';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastProps<T> extends AriaLabelingProps {\n /** The toast object. */\n toast: QueuedToast<T>\n}\n\nexport interface ToastAria {\n /** Props for the toast container, non-modal dialog element. */\n toastProps: DOMAttributes,\n /** Props for the toast content alert message. */\n contentProps: DOMAttributes,\n /** Props for the toast title element. */\n titleProps: DOMAttributes,\n /** Props for the toast description element, if any. */\n descriptionProps: DOMAttributes,\n /** Props for the toast close button. */\n closeButtonProps: AriaButtonProps\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast component.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nexport function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref: RefObject<FocusableElement | null>): ToastAria {\n let {\n key,\n timer,\n timeout\n } = props.toast;\n\n useEffect(() => {\n if (timer == null || timeout == null) {\n return;\n }\n\n timer.reset(timeout);\n return () => {\n timer.pause();\n };\n }, [timer, timeout]);\n\n let titleId = useId();\n let descriptionId = useSlotId();\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n\n // This is required for NVDA announcements, without it NVDA will NOT announce the toast when it appears.\n // Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5\n // but toasts don't always have animations.\n let [isVisible, setIsVisible] = useState(false);\n useLayoutEffect(() => {\n setIsVisible(true);\n }, []);\n\n let toastProps = filterDOMProps(props, {labelable: true});\n\n return {\n toastProps: {\n ...toastProps,\n role: 'alertdialog',\n 'aria-modal': 'false',\n 'aria-labelledby': props['aria-labelledby'] || titleId,\n 'aria-describedby': props['aria-describedby'] || descriptionId,\n tabIndex: 0\n },\n contentProps: {\n role: 'alert',\n 'aria-atomic': 'true',\n 'aria-hidden': isVisible ? undefined : 'true'\n },\n titleProps: {\n id: titleId\n },\n descriptionProps: {\n id: descriptionId\n },\n closeButtonProps: {\n 'aria-label': stringFormatter.format('close'),\n onPress: () => state.close(key)\n }\n };\n}\n"],"names":[],"version":3,"file":"useToast.module.js.map"}
|
|
@@ -41,10 +41,12 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
41
41
|
}, ref);
|
|
42
42
|
let isHovered = (0, $eO7VF$react.useRef)(false);
|
|
43
43
|
let isFocused = (0, $eO7VF$react.useRef)(false);
|
|
44
|
-
let updateTimers = (0, $eO7VF$
|
|
44
|
+
let updateTimers = (0, $eO7VF$react.useCallback)(()=>{
|
|
45
45
|
if (isHovered.current || isFocused.current) state.pauseAll();
|
|
46
46
|
else state.resumeAll();
|
|
47
|
-
}
|
|
47
|
+
}, [
|
|
48
|
+
state
|
|
49
|
+
]);
|
|
48
50
|
let { hoverProps: hoverProps } = (0, $eO7VF$reactariainteractions.useHover)({
|
|
49
51
|
onHoverStart: ()=>{
|
|
50
52
|
isHovered.current = true;
|
|
@@ -113,8 +115,7 @@ function $eda7c6204a682dd4$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
113
115
|
prevVisibleToasts.current = state.visibleToasts;
|
|
114
116
|
}, [
|
|
115
117
|
state.visibleToasts,
|
|
116
|
-
ref
|
|
117
|
-
updateTimers
|
|
118
|
+
ref
|
|
118
119
|
]);
|
|
119
120
|
let lastFocused = (0, $eO7VF$react.useRef)(null);
|
|
120
121
|
let { focusWithinProps: focusWithinProps } = (0, $eO7VF$reactariainteractions.useFocusWithin)({
|
|
@@ -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,GAA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ion.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, useEffectEvent, useLayoutEffect} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ToastState} from '@react-stately/toast';\nimport {useEffect, useRef} from 'react';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement | null>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {count: state.visibleToasts.length})\n }, ref);\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n let updateTimers = useEffectEvent(() => {\n if (isHovered.current || isFocused.current) {\n state.pauseAll();\n } else {\n state.resumeAll();\n }\n });\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, updateTimers]);\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":"useToastR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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"}
|
package/dist/useToastRegion.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import $ckyCP$intlStringsmodulejs from "./intlStrings.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import {useLayoutEffect as $ckyCP$useLayoutEffect, focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
|
|
3
3
|
import {useHover as $ckyCP$useHover, getInteractionModality as $ckyCP$getInteractionModality, useFocusWithin as $ckyCP$useFocusWithin} from "@react-aria/interactions";
|
|
4
|
-
import {useRef as $ckyCP$useRef, useEffect as $ckyCP$useEffect} from "react";
|
|
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";
|
|
6
6
|
import {useLocalizedStringFormatter as $ckyCP$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
7
7
|
|
|
@@ -35,10 +35,12 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
35
35
|
}, ref);
|
|
36
36
|
let isHovered = (0, $ckyCP$useRef)(false);
|
|
37
37
|
let isFocused = (0, $ckyCP$useRef)(false);
|
|
38
|
-
let updateTimers = (0, $ckyCP$
|
|
38
|
+
let updateTimers = (0, $ckyCP$useCallback)(()=>{
|
|
39
39
|
if (isHovered.current || isFocused.current) state.pauseAll();
|
|
40
40
|
else state.resumeAll();
|
|
41
|
-
}
|
|
41
|
+
}, [
|
|
42
|
+
state
|
|
43
|
+
]);
|
|
42
44
|
let { hoverProps: hoverProps } = (0, $ckyCP$useHover)({
|
|
43
45
|
onHoverStart: ()=>{
|
|
44
46
|
isHovered.current = true;
|
|
@@ -107,8 +109,7 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
107
109
|
prevVisibleToasts.current = state.visibleToasts;
|
|
108
110
|
}, [
|
|
109
111
|
state.visibleToasts,
|
|
110
|
-
ref
|
|
111
|
-
updateTimers
|
|
112
|
+
ref
|
|
112
113
|
]);
|
|
113
114
|
let lastFocused = (0, $ckyCP$useRef)(null);
|
|
114
115
|
let { focusWithinProps: focusWithinProps } = (0, $ckyCP$useFocusWithin)({
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import $ckyCP$intlStringsmodulejs from "./intlStrings.module.js";
|
|
2
|
-
import {
|
|
2
|
+
import {useLayoutEffect as $ckyCP$useLayoutEffect, focusWithoutScrolling as $ckyCP$focusWithoutScrolling, mergeProps as $ckyCP$mergeProps} from "@react-aria/utils";
|
|
3
3
|
import {useHover as $ckyCP$useHover, getInteractionModality as $ckyCP$getInteractionModality, useFocusWithin as $ckyCP$useFocusWithin} from "@react-aria/interactions";
|
|
4
|
-
import {useRef as $ckyCP$useRef, useEffect as $ckyCP$useEffect} from "react";
|
|
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";
|
|
6
6
|
import {useLocalizedStringFormatter as $ckyCP$useLocalizedStringFormatter} from "@react-aria/i18n";
|
|
7
7
|
|
|
@@ -35,10 +35,12 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
35
35
|
}, ref);
|
|
36
36
|
let isHovered = (0, $ckyCP$useRef)(false);
|
|
37
37
|
let isFocused = (0, $ckyCP$useRef)(false);
|
|
38
|
-
let updateTimers = (0, $ckyCP$
|
|
38
|
+
let updateTimers = (0, $ckyCP$useCallback)(()=>{
|
|
39
39
|
if (isHovered.current || isFocused.current) state.pauseAll();
|
|
40
40
|
else state.resumeAll();
|
|
41
|
-
}
|
|
41
|
+
}, [
|
|
42
|
+
state
|
|
43
|
+
]);
|
|
42
44
|
let { hoverProps: hoverProps } = (0, $ckyCP$useHover)({
|
|
43
45
|
onHoverStart: ()=>{
|
|
44
46
|
isHovered.current = true;
|
|
@@ -107,8 +109,7 @@ function $6cc546b19ee7130a$export$b8cbbb20a51697de(props, state, ref) {
|
|
|
107
109
|
prevVisibleToasts.current = state.visibleToasts;
|
|
108
110
|
}, [
|
|
109
111
|
state.visibleToasts,
|
|
110
|
-
ref
|
|
111
|
-
updateTimers
|
|
112
|
+
ref
|
|
112
113
|
]);
|
|
113
114
|
let lastFocused = (0, $ckyCP$useRef)(null);
|
|
114
115
|
let { focusWithinProps: focusWithinProps } = (0, $ckyCP$useFocusWithin)({
|
|
@@ -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,IA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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, useEffectEvent, useLayoutEffect} from '@react-aria/utils';\nimport {getInteractionModality, useFocusWithin, useHover} from '@react-aria/interactions';\n// @ts-ignore\nimport intlMessages from '../intl/*.json';\nimport {ToastState} from '@react-stately/toast';\nimport {useEffect, useRef} from 'react';\nimport {useLandmark} from '@react-aria/landmark';\nimport {useLocalizedStringFormatter} from '@react-aria/i18n';\n\nexport interface AriaToastRegionProps extends AriaLabelingProps {\n /**\n * An accessibility label for the toast region.\n * @default \"Notifications\"\n */\n 'aria-label'?: string\n}\n\nexport interface ToastRegionAria {\n /** Props for the landmark region element. */\n regionProps: DOMAttributes\n}\n\n/**\n * Provides the behavior and accessibility implementation for a toast region containing one or more toasts.\n * Toasts display brief, temporary notifications of actions, errors, or other events in an application.\n */\nexport function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState<T>, ref: RefObject<HTMLElement | null>): ToastRegionAria {\n let stringFormatter = useLocalizedStringFormatter(intlMessages, '@react-aria/toast');\n let {landmarkProps} = useLandmark({\n role: 'region',\n 'aria-label': props['aria-label'] || stringFormatter.format('notifications', {count: state.visibleToasts.length})\n }, ref);\n\n let isHovered = useRef(false);\n let isFocused = useRef(false);\n let updateTimers = useEffectEvent(() => {\n if (isHovered.current || isFocused.current) {\n state.pauseAll();\n } else {\n state.resumeAll();\n }\n });\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, updateTimers]);\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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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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@react-aria/toast",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.9",
|
|
4
4
|
"description": "Spectrum UI components in React",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"main": "dist/main.js",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"url": "https://github.com/adobe/react-spectrum"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@react-aria/i18n": "^3.12.
|
|
30
|
-
"@react-aria/interactions": "^3.
|
|
31
|
-
"@react-aria/landmark": "^3.0.
|
|
32
|
-
"@react-aria/utils": "^3.
|
|
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
33
|
"@react-stately/toast": "^3.1.2",
|
|
34
34
|
"@react-types/button": "^3.14.1",
|
|
35
35
|
"@react-types/shared": "^3.32.1",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
44
44
|
},
|
|
45
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "4d838da5bfe36abb35aed166995a9ef63825370f"
|
|
46
46
|
}
|
package/src/useToast.ts
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import {AriaButtonProps} from '@react-types/button';
|
|
14
14
|
import {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
|
|
15
|
-
import {filterDOMProps, useId, useSlotId} from '@react-aria/utils';
|
|
15
|
+
import {filterDOMProps, useId, useLayoutEffect, useSlotId} from '@react-aria/utils';
|
|
16
16
|
// @ts-ignore
|
|
17
17
|
import intlMessages from '../intl/*.json';
|
|
18
18
|
import {QueuedToast, ToastState} from '@react-stately/toast';
|
|
@@ -68,7 +68,7 @@ export function useToast<T>(props: AriaToastProps<T>, state: ToastState<T>, ref:
|
|
|
68
68
|
// Originally was tied to animationStart/End via https://github.com/adobe/react-spectrum/pull/6223/commits/e22e319df64958e822ab7cd9685e96818cae9ba5
|
|
69
69
|
// but toasts don't always have animations.
|
|
70
70
|
let [isVisible, setIsVisible] = useState(false);
|
|
71
|
-
|
|
71
|
+
useLayoutEffect(() => {
|
|
72
72
|
setIsVisible(true);
|
|
73
73
|
}, []);
|
|
74
74
|
|
package/src/useToastRegion.ts
CHANGED
|
@@ -11,12 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import {AriaLabelingProps, DOMAttributes, FocusableElement, RefObject} from '@react-types/shared';
|
|
14
|
-
import {focusWithoutScrolling, mergeProps,
|
|
14
|
+
import {focusWithoutScrolling, 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';
|
|
18
18
|
import {ToastState} from '@react-stately/toast';
|
|
19
|
-
import {useEffect, useRef} from 'react';
|
|
19
|
+
import {useCallback, useEffect, useRef} from 'react';
|
|
20
20
|
import {useLandmark} from '@react-aria/landmark';
|
|
21
21
|
import {useLocalizedStringFormatter} from '@react-aria/i18n';
|
|
22
22
|
|
|
@@ -46,13 +46,13 @@ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState
|
|
|
46
46
|
|
|
47
47
|
let isHovered = useRef(false);
|
|
48
48
|
let isFocused = useRef(false);
|
|
49
|
-
let updateTimers =
|
|
49
|
+
let updateTimers = useCallback(() => {
|
|
50
50
|
if (isHovered.current || isFocused.current) {
|
|
51
51
|
state.pauseAll();
|
|
52
52
|
} else {
|
|
53
53
|
state.resumeAll();
|
|
54
54
|
}
|
|
55
|
-
});
|
|
55
|
+
}, [state]);
|
|
56
56
|
|
|
57
57
|
let {hoverProps} = useHover({
|
|
58
58
|
onHoverStart: () => {
|
|
@@ -133,7 +133,7 @@ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
prevVisibleToasts.current = state.visibleToasts;
|
|
136
|
-
}, [state.visibleToasts, ref
|
|
136
|
+
}, [state.visibleToasts, ref]);
|
|
137
137
|
|
|
138
138
|
let lastFocused = useRef<FocusableElement | null>(null);
|
|
139
139
|
let {focusWithinProps} = useFocusWithin({
|