@@ -116,7 +116,10 @@ const ToastRoot = React.forwardRef(function ToastRoot(
116
116
) ;
117
117
118
118
useEnhancedEffect ( ( ) => {
119
- if ( ! rootRef . current ) return ;
119
+ if ( ! rootRef . current ) {
120
+ return undefined ;
121
+ }
122
+
120
123
function setHeights ( ) {
121
124
const height = rootRef . current ?. offsetHeight ;
122
125
setToasts ( ( prev ) =>
@@ -132,14 +135,18 @@ const ToastRoot = React.forwardRef(function ToastRoot(
132
135
) ,
133
136
) ;
134
137
}
138
+
135
139
setHeights ( ) ;
140
+
136
141
if ( typeof ResizeObserver === 'function' ) {
137
142
const resizeObserver = new ResizeObserver ( setHeights ) ;
138
143
resizeObserver . observe ( rootRef . current ) ;
139
144
return ( ) => {
140
145
resizeObserver . disconnect ( ) ;
141
146
} ;
142
147
}
148
+
149
+ return undefined ;
143
150
} , [ toast . id , setToasts ] ) ;
144
151
145
152
const offset = React . useMemo ( ( ) => {
@@ -245,7 +252,9 @@ const ToastRoot = React.forwardRef(function ToastRoot(
245
252
}
246
253
247
254
function handlePointerMove ( event : React . PointerEvent ) {
248
- if ( ! isDragging ) return ;
255
+ if ( ! isDragging ) {
256
+ return ;
257
+ }
249
258
250
259
const deltaX = event . clientX - dragStartPosRef . current . x ;
251
260
const deltaY = event . clientY - dragStartPosRef . current . y ;
@@ -273,19 +282,23 @@ const ToastRoot = React.forwardRef(function ToastRoot(
273
282
let candidate : 'up' | 'down' | 'left' | 'right' | undefined ;
274
283
if ( ! intendedSwipeDirectionRef . current ) {
275
284
if ( lockedDirection === 'vertical' ) {
276
- candidate = deltaY > 0 ? 'down' : deltaY < 0 ? 'up' : undefined ;
285
+ if ( deltaY > 0 ) {
286
+ candidate = 'down' ;
287
+ } else if ( deltaY < 0 ) {
288
+ candidate = 'up' ;
289
+ }
277
290
} else if ( lockedDirection === 'horizontal' ) {
278
- candidate = deltaX > 0 ? 'right' : deltaX < 0 ? 'left' : undefined ;
291
+ if ( deltaY > 0 ) {
292
+ candidate = 'right' ;
293
+ } else if ( deltaY < 0 ) {
294
+ candidate = 'left' ;
295
+ }
296
+ } else if ( Math . abs ( deltaX ) >= Math . abs ( deltaY ) ) {
297
+ candidate = deltaX > 0 ? 'right' : 'left' ;
279
298
} else {
280
- candidate =
281
- Math . abs ( deltaX ) >= Math . abs ( deltaY )
282
- ? deltaX > 0
283
- ? 'right'
284
- : 'left'
285
- : deltaY > 0
286
- ? 'down'
287
- : 'up' ;
299
+ candidate = deltaY > 0 ? 'down' : 'up' ;
288
300
}
301
+
289
302
if ( candidate && swipeDirections . includes ( candidate ) ) {
290
303
intendedSwipeDirectionRef . current = candidate ;
291
304
maxSwipeDisplacementRef . current = getDisplacement ( candidate , deltaX , deltaY ) ;
@@ -359,16 +372,24 @@ const ToastRoot = React.forwardRef(function ToastRoot(
359
372
for ( const direction of swipeDirections ) {
360
373
switch ( direction ) {
361
374
case 'right' :
362
- if ( deltaX > SWIPE_THRESHOLD ) shouldClose = true ;
375
+ if ( deltaX > SWIPE_THRESHOLD ) {
376
+ shouldClose = true ;
377
+ }
363
378
break ;
364
379
case 'left' :
365
- if ( deltaX < - SWIPE_THRESHOLD ) shouldClose = true ;
380
+ if ( deltaX < - SWIPE_THRESHOLD ) {
381
+ shouldClose = true ;
382
+ }
366
383
break ;
367
384
case 'down' :
368
- if ( deltaY > SWIPE_THRESHOLD ) shouldClose = true ;
385
+ if ( deltaY > SWIPE_THRESHOLD ) {
386
+ shouldClose = true ;
387
+ }
369
388
break ;
370
389
case 'up' :
371
- if ( deltaY < - SWIPE_THRESHOLD ) shouldClose = true ;
390
+ if ( deltaY < - SWIPE_THRESHOLD ) {
391
+ shouldClose = true ;
392
+ }
372
393
break ;
373
394
default :
374
395
break ;
@@ -406,7 +427,7 @@ const ToastRoot = React.forwardRef(function ToastRoot(
406
427
React . useEffect ( ( ) => {
407
428
const element = rootRef . current ;
408
429
if ( ! element ) {
409
- return ;
430
+ return undefined ;
410
431
}
411
432
412
433
function preventDefaultTouchStart ( event : TouchEvent ) {
@@ -513,7 +534,7 @@ const ToastRoot = React.forwardRef(function ToastRoot(
513
534
// of the component. We need to wait until the next tick to render the children
514
535
// so that screen readers can announce the contents.
515
536
children : (
516
- < >
537
+ < React . Fragment >
517
538
{ children }
518
539
{ ! focused && (
519
540
< div
@@ -523,14 +544,14 @@ const ToastRoot = React.forwardRef(function ToastRoot(
523
544
: { role : 'status' , 'aria-live' : 'polite' } ) }
524
545
>
525
546
{ renderChildren && (
526
- < >
547
+ < React . Fragment >
527
548
< div > { toast . title } </ div >
528
549
< div > { toast . description } </ div >
529
- </ >
550
+ </ React . Fragment >
530
551
) }
531
552
</ div >
532
553
) }
533
- </ >
554
+ </ React . Fragment >
534
555
) ,
535
556
} ,
536
557
other ,
0 commit comments