@@ -19,10 +19,10 @@ import type { FloatingTreeType, MaybeGetter } from "../types.js";
19
19
import { useFloatingTree } from "../components/floating-tree/hooks.svelte.js" ;
20
20
import { getChildren } from "../internal/get-children.js" ;
21
21
import { on } from "svelte/events" ;
22
- import { executeCallbacks } from "../internal/execute-callbacks.js" ;
23
22
import { extract } from "../internal/extract.js" ;
24
23
import { watch } from "../internal/watch.svelte.js" ;
25
24
import type { ElementProps } from "./use-interactions.svelte.js" ;
25
+ import { untrack } from "svelte" ;
26
26
27
27
const bubbleHandlerKeys = {
28
28
pointerdown : "onpointerdown" ,
@@ -164,10 +164,11 @@ class DismissInteraction implements ElementProps {
164
164
165
165
$effect ( ( ) => {
166
166
if ( ! this . context . open || ! this . #enabled) return ;
167
-
168
- this . context . data . __escapeKeyBubbles = this . #bubbleOptions. escapeKey ;
169
- this . context . data . __outsidePressBubbles =
170
- this . #bubbleOptions. outsidePress ;
167
+ untrack ( ( ) => {
168
+ this . context . data . __escapeKeyBubbles = this . #bubbleOptions. escapeKey ;
169
+ this . context . data . __outsidePressBubbles =
170
+ this . #bubbleOptions. outsidePress ;
171
+ } ) ;
171
172
172
173
let compositionTimeout = - 1 ;
173
174
@@ -206,6 +207,7 @@ class DismissInteraction implements ElementProps {
206
207
this . #captureOptions. escapeKey
207
208
? this . #closeOnEscapeKeyDownCapture
208
209
: this . #closeOnEscapeKeyDown,
210
+ { capture : this . #captureOptions. escapeKey } ,
209
211
) ,
210
212
on ( doc , "compositionstart" , handleCompositionStart ) ,
211
213
on ( doc , "compositionend" , handleCompositionEnd ) ,
@@ -220,6 +222,7 @@ class DismissInteraction implements ElementProps {
220
222
this . #captureOptions. outsidePress
221
223
? this . #closeOnPressOutsideCapture
222
224
: this . #closeOnPressOutside,
225
+ { capture : this . #captureOptions. outsidePress } ,
223
226
) ,
224
227
) ;
225
228
}
@@ -260,7 +263,9 @@ class DismissInteraction implements ElementProps {
260
263
}
261
264
262
265
return ( ) => {
263
- executeCallbacks ( ...listenersToRemove ) ;
266
+ for ( const removeListener of listenersToRemove ) {
267
+ removeListener ( ) ;
268
+ }
264
269
window . clearTimeout ( compositionTimeout ) ;
265
270
} ;
266
271
} ) ;
@@ -270,7 +275,7 @@ class DismissInteraction implements ElementProps {
270
275
} ) ;
271
276
}
272
277
273
- #closeOnEscapeKeyDown( event : KeyboardEvent ) {
278
+ #closeOnEscapeKeyDown = ( event : KeyboardEvent ) => {
274
279
if (
275
280
! this . context . open ||
276
281
! this . #enabled ||
@@ -290,31 +295,27 @@ class DismissInteraction implements ElementProps {
290
295
event . stopPropagation ( ) ;
291
296
292
297
if ( children . length > 0 ) {
293
- let shouldDismiss = true ;
294
-
295
- for ( const child of children ) {
296
- if ( child . context ?. open && ! child . context . data . __escapeKeyBubbles ) {
297
- shouldDismiss = false ;
298
- break ;
299
- }
300
- }
298
+ const hasOpenChild = children . some (
299
+ ( child ) =>
300
+ child . context ?. open && ! child . context . data . __escapeKeyBubbles ,
301
+ ) ;
301
302
302
- if ( ! shouldDismiss ) return ;
303
+ if ( hasOpenChild ) return ;
303
304
}
304
305
}
305
306
306
307
this . context . onOpenChange ( false , event , "escape-key" ) ;
307
- }
308
+ } ;
308
309
309
- #closeOnEscapeKeyDownCapture( event : KeyboardEvent ) {
310
+ #closeOnEscapeKeyDownCapture = ( event : KeyboardEvent ) => {
310
311
const callback = ( ) => {
311
312
this . #closeOnEscapeKeyDown( event ) ;
312
313
getTarget ( event ) ?. removeEventListener ( "keydown" , callback ) ;
313
314
} ;
314
315
getTarget ( event ) ?. addEventListener ( "keydown" , callback ) ;
315
- }
316
+ } ;
316
317
317
- #closeOnPressOutside( event : MouseEvent ) {
318
+ #closeOnPressOutside = ( event : MouseEvent ) => {
318
319
const localInsideTree = this . #insideTree;
319
320
this . #insideTree = false ;
320
321
@@ -373,7 +374,7 @@ class DismissInteraction implements ElementProps {
373
374
}
374
375
375
376
// Check if the click occurred on the scrollbar
376
- if ( isHTMLElement ( target ) ) {
377
+ if ( isHTMLElement ( target ) && this . context . floating ) {
377
378
const lastTraversableNode = isLastTraversableNode ( target ) ;
378
379
const style = getComputedStyle ( target ) ;
379
380
const scrollRe = / a u t o | s c r o l l / ;
@@ -431,28 +432,24 @@ class DismissInteraction implements ElementProps {
431
432
}
432
433
433
434
if ( children . length > 0 ) {
434
- let shouldDismiss = true ;
435
-
436
- for ( const child of children ) {
437
- if ( child . context ?. open && ! child . context . data . __outsidePressBubbles ) {
438
- shouldDismiss = false ;
439
- break ;
440
- }
441
- }
435
+ const hasOpenChild = children . some (
436
+ ( child ) =>
437
+ child . context ?. open && ! child . context . data . __outsidePressBubbles ,
438
+ ) ;
442
439
443
- if ( ! shouldDismiss ) return ;
440
+ if ( hasOpenChild ) return ;
444
441
}
445
442
446
443
this . context . onOpenChange ( false , event , "outside-press" ) ;
447
- }
444
+ } ;
448
445
449
- #closeOnPressOutsideCapture( event : MouseEvent ) {
446
+ #closeOnPressOutsideCapture = ( event : MouseEvent ) => {
450
447
const callback = ( ) => {
451
448
this . #closeOnPressOutside( event ) ;
452
449
getTarget ( event ) ?. removeEventListener ( this . #outsidePressEvent, callback ) ;
453
450
} ;
454
451
getTarget ( event ) ?. addEventListener ( this . #outsidePressEvent, callback ) ;
455
- }
452
+ } ;
456
453
457
454
#reference = $derived . by ( ( ) => {
458
455
if ( ! this . #enabled) return { } ;
0 commit comments