@@ -58,29 +58,29 @@ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState
58
58
prevVisibleToasts . current = state . visibleToasts ;
59
59
return ;
60
60
}
61
- // Get a list of all removed toasts by index.
62
- let removedToasts = prevVisibleToasts . current
61
+ // Get a list of all toasts by index and add info if they are removed .
62
+ let allToasts = prevVisibleToasts . current
63
63
. map ( ( t , i ) => ( {
64
64
...t ,
65
65
i,
66
66
isRemoved : ! state . visibleToasts . some ( t2 => t . key === t2 . key )
67
67
} ) ) ;
68
68
69
- let removedToastIndex = removedToasts . findIndex ( t => t . i === focusedToast . current ) ;
69
+ let removedFocusedToastIndex = allToasts . findIndex ( t => t . i === focusedToast . current ) ;
70
70
71
71
// If the focused toast was removed, focus the next or previous toast.
72
- if ( removedToastIndex > - 1 ) {
72
+ if ( removedFocusedToastIndex > - 1 ) {
73
73
let i = 0 ;
74
74
let nextToast ;
75
75
let prevToast ;
76
- while ( i <= removedToastIndex ) {
77
- if ( ! removedToasts [ i ] . isRemoved ) {
76
+ while ( i <= removedFocusedToastIndex ) {
77
+ if ( ! allToasts [ i ] . isRemoved ) {
78
78
prevToast = Math . max ( 0 , i - 1 ) ;
79
79
}
80
80
i ++ ;
81
81
}
82
- while ( i < removedToasts . length ) {
83
- if ( ! removedToasts [ i ] . isRemoved ) {
82
+ while ( i < allToasts . length ) {
83
+ if ( ! allToasts [ i ] . isRemoved ) {
84
84
nextToast = i - 1 ;
85
85
break ;
86
86
}
@@ -92,6 +92,7 @@ export function useToastRegion<T>(props: AriaToastRegionProps, state: ToastState
92
92
prevToast = 0 ;
93
93
}
94
94
95
+ // prioritize going to newer toasts
95
96
if ( prevToast >= 0 && prevToast < toasts . current . length ) {
96
97
focusWithoutScrolling ( toasts . current [ prevToast ] ) ;
97
98
} else if ( nextToast >= 0 && nextToast < toasts . current . length ) {
0 commit comments