mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
fix(toast): toastRegion leftover in DOM (#5508)
This commit is contained in:
parent
2cb6ecff93
commit
60118379f5
5
.changeset/silver-items-doubt.md
Normal file
5
.changeset/silver-items-doubt.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
"@heroui/toast": patch
|
||||
---
|
||||
|
||||
fixed toastRegion leftover in DOM (#5502)
|
||||
@ -4,7 +4,7 @@ import type {ToastProps, ToastPlacement} from "./use-toast";
|
||||
|
||||
import {ToastQueue, useToastQueue} from "@react-stately/toast";
|
||||
import {useProviderContext} from "@heroui/system";
|
||||
import {AnimatePresence, LazyMotion} from "framer-motion";
|
||||
import {LazyMotion} from "framer-motion";
|
||||
|
||||
import {ToastRegion} from "./toast-region";
|
||||
|
||||
@ -45,19 +45,17 @@ export const ToastProvider = ({
|
||||
|
||||
return (
|
||||
<LazyMotion features={loadFeatures}>
|
||||
<AnimatePresence>
|
||||
{toastQueue.visibleToasts.length > 0 ? (
|
||||
<ToastRegion
|
||||
disableAnimation={disableAnimation}
|
||||
maxVisibleToasts={maxVisibleToasts}
|
||||
placement={placement}
|
||||
toastOffset={toastOffset}
|
||||
toastProps={toastProps}
|
||||
toastQueue={toastQueue}
|
||||
{...regionProps}
|
||||
/>
|
||||
) : null}
|
||||
</AnimatePresence>
|
||||
{toastQueue.visibleToasts.length > 0 && (
|
||||
<ToastRegion
|
||||
disableAnimation={disableAnimation}
|
||||
maxVisibleToasts={maxVisibleToasts}
|
||||
placement={placement}
|
||||
toastOffset={toastOffset}
|
||||
toastProps={toastProps}
|
||||
toastQueue={toastQueue}
|
||||
{...regionProps}
|
||||
/>
|
||||
)}
|
||||
</LazyMotion>
|
||||
);
|
||||
};
|
||||
|
||||
@ -8,6 +8,7 @@ import {useToastRegion} from "@react-aria/toast";
|
||||
import {useHover} from "@react-aria/interactions";
|
||||
import {toastRegion} from "@heroui/theme";
|
||||
import {clsx, mergeProps} from "@heroui/shared-utils";
|
||||
import {AnimatePresence} from "framer-motion";
|
||||
|
||||
import Toast from "./toast";
|
||||
|
||||
@ -81,37 +82,39 @@ export function ToastRegion<T extends ToastProps>({
|
||||
data-placement={placement}
|
||||
onTouchStart={handleTouchStart}
|
||||
>
|
||||
{[...toastQueue.visibleToasts].reverse().map((toast: QueuedToast<ToastProps>, index) => {
|
||||
if (disableAnimation && total - index > maxVisibleToasts) {
|
||||
<AnimatePresence>
|
||||
{[...toastQueue.visibleToasts].reverse().map((toast: QueuedToast<ToastProps>, index) => {
|
||||
if (disableAnimation && total - index > maxVisibleToasts) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (
|
||||
disableAnimation ||
|
||||
total - index <= 4 ||
|
||||
(isHovered && total - index <= maxVisibleToasts + 1)
|
||||
) {
|
||||
return (
|
||||
<Toast
|
||||
key={toast.key}
|
||||
state={toastQueue}
|
||||
toast={toast}
|
||||
{...mergeProps(toastProps, toast.content)}
|
||||
disableAnimation={disableAnimation}
|
||||
heights={heights}
|
||||
index={index}
|
||||
isRegionExpanded={isHovered || isTouched}
|
||||
maxVisibleToasts={maxVisibleToasts}
|
||||
placement={placement}
|
||||
setHeights={setHeights}
|
||||
toastOffset={toastOffset}
|
||||
total={total}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
if (
|
||||
disableAnimation ||
|
||||
total - index <= 4 ||
|
||||
(isHovered && total - index <= maxVisibleToasts + 1)
|
||||
) {
|
||||
return (
|
||||
<Toast
|
||||
key={toast.key}
|
||||
state={toastQueue}
|
||||
toast={toast}
|
||||
{...mergeProps(toastProps, toast.content)}
|
||||
disableAnimation={disableAnimation}
|
||||
heights={heights}
|
||||
index={index}
|
||||
isRegionExpanded={isHovered || isTouched}
|
||||
maxVisibleToasts={maxVisibleToasts}
|
||||
placement={placement}
|
||||
setHeights={setHeights}
|
||||
toastOffset={toastOffset}
|
||||
total={total}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
})}
|
||||
})}
|
||||
</AnimatePresence>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user