@@ -47,18 +47,6 @@ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState
47
47
let isHovered = useRef ( false ) ;
48
48
let pointerPosition = useRef ( { x : 0 , y : 0 } ) ;
49
49
50
- useEffect ( ( ) => {
51
- let onPointerMove = ( e : PointerEvent ) => {
52
- pointerPosition . current = { x : e . clientX , y : e . clientY } ;
53
- } ;
54
- if ( state . visibleToasts . length > 1 ) {
55
- document . addEventListener ( 'pointermove' , onPointerMove ) ;
56
- }
57
- return ( ) => {
58
- document . removeEventListener ( 'pointermove' , onPointerMove ) ;
59
- } ;
60
- } , [ state . visibleToasts . length ] ) ;
61
-
62
50
let { hoverProps} = useHover ( {
63
51
onHoverStart : ( ) => {
64
52
isHovered . current = true ;
@@ -87,6 +75,20 @@ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState
87
75
prevToastCount . current = currentCount ;
88
76
} , [ ref , state ] ) ;
89
77
78
+ useEffect ( ( ) => {
79
+ let onPointerMove = ( e : PointerEvent ) => {
80
+ pointerPosition . current = { x : e . clientX , y : e . clientY } ;
81
+ } ;
82
+ if ( prevToastCount . current === 1 && state . visibleToasts . length === 2 ) {
83
+ document . addEventListener ( 'pointermove' , onPointerMove ) ;
84
+ } else if ( prevToastCount . current === 2 && state . visibleToasts . length === 1 ) {
85
+ document . removeEventListener ( 'pointermove' , onPointerMove ) ;
86
+ }
87
+ return ( ) => {
88
+ document . removeEventListener ( 'pointermove' , onPointerMove ) ;
89
+ } ;
90
+ } , [ state . visibleToasts ] ) ;
91
+
90
92
// Manage focus within the toast region.
91
93
// If a focused containing toast is removed, move focus to the next toast, or the previous toast if there is no next toast.
92
94
// We might be making an assumption with how this works if someone implements the priority queue differently, or
0 commit comments