@@ -221,6 +221,7 @@ class ListNavigationState {
221
221
#parentId: string | null = null ;
222
222
#tree: FloatingTreeType | null = null ;
223
223
#index = $state ( this . #selectedIndex ?? - 1 ) ;
224
+
224
225
#typeableComboboxReference = $derived . by ( ( ) =>
225
226
isTypeableCombobox ( this . context . domReference ) ,
226
227
) ;
@@ -232,9 +233,8 @@ class ListNavigationState {
232
233
233
234
#activeId = $state < string | undefined > ( ) ;
234
235
#virtualId = $state < string | undefined > ( ) ;
235
- #previousMounted: boolean ;
236
- #previousOpen: boolean ;
237
- #previousOnNavigate: ( ) => void ;
236
+ #mounted = false ;
237
+ #previousOpen = false ;
238
238
#hasActiveIndex = $derived . by ( ( ) => this . #activeIndex != null ) ;
239
239
240
240
#ariaActiveDescendantProp = $derived . by ( ( ) => {
@@ -273,9 +273,7 @@ class ListNavigationState {
273
273
this . #virtualItemRef = this . opts . virtualItemRef ;
274
274
this . #parentId = useFloatingParentNodeId ( ) ;
275
275
this . #tree = useFloatingTree ( ) ;
276
- this . #previousMounted = ! ! this . context . floating ;
277
- this . #previousOpen = this . context . open ;
278
- this . #previousOnNavigate = this . #onNavigate;
276
+ this . #mounted = ! ! this . context . floating ;
279
277
280
278
// Sync `selectedIndex` to be the `activeIndex` upon opening the floating
281
279
// element. Also, reset `activeIndex` upon closing the floating element.
@@ -296,7 +294,7 @@ class ListNavigationState {
296
294
this . #index = this . #selectedIndex;
297
295
this . #onNavigate( ) ;
298
296
}
299
- } else if ( this . #previousMounted ) {
297
+ } else if ( this . #mounted ) {
300
298
this . #index = - 1 ;
301
299
this . #onNavigate( ) ;
302
300
}
@@ -331,14 +329,14 @@ class ListNavigationState {
331
329
}
332
330
333
331
// Reset while the floating element was open (e.g. the list changed).
334
- if ( this . #previousMounted ) {
332
+ if ( this . #mounted ) {
335
333
this . #index = - 1 ;
336
334
this . #focusItem( ) ;
337
335
}
338
336
339
337
// Initial sync.
340
338
if (
341
- ( ! this . #previousOpen || ! this . #previousMounted ) &&
339
+ ( ! this . #previousOpen || ! this . #mounted ) &&
342
340
this . #focusItemOnOpen &&
343
341
( this . #key != null ||
344
342
( this . #focusItemOnOpen === true && this . #key == null ) )
@@ -397,7 +395,7 @@ class ListNavigationState {
397
395
this . context . floating ||
398
396
! this . #tree ||
399
397
this . #virtual ||
400
- ! this . #previousMounted
398
+ ! this . #mounted
401
399
) {
402
400
return ;
403
401
}
@@ -446,17 +444,13 @@ class ListNavigationState {
446
444
) ;
447
445
448
446
$effect . pre ( ( ) => {
449
- this . #previousMounted = ! ! this . context . floating ;
447
+ this . #mounted = ! ! this . context . floating ;
450
448
} ) ;
451
449
452
450
$effect . pre ( ( ) => {
453
451
this . #previousOpen = this . context . open ;
454
452
} ) ;
455
453
456
- $effect . pre ( ( ) => {
457
- this . #previousOnNavigate = this . #onNavigate;
458
- } ) ;
459
-
460
454
$effect . pre ( ( ) => {
461
455
this . #focusItemOnOpen = this . #focusItemOnOpenProp;
462
456
} ) ;
@@ -472,7 +466,6 @@ class ListNavigationState {
472
466
}
473
467
474
468
#onNavigate = ( ) => {
475
- console . log ( "calling on navigate" ) ;
476
469
this . opts . onNavigate ?.( this . #index === - 1 ? null : this . #index) ;
477
470
} ;
478
471
@@ -811,6 +804,7 @@ class ListNavigationState {
811
804
812
805
#referenceOnKeyDown = ( event : KeyboardEvent ) => {
813
806
this . #isPointerModality = false ;
807
+ const isOpen = this . context . open ;
814
808
815
809
const isArrowKey = event . key . startsWith ( "Arrow" ) ;
816
810
const isHomeOrEndKey = [ "Home" , "End" ] . includes ( event . key ) ;
@@ -831,7 +825,7 @@ class ListNavigationState {
831
825
event . key === "Enter" ||
832
826
event . key . trim ( ) === "" ;
833
827
834
- if ( this . #virtual && this . context . open ) {
828
+ if ( this . #virtual && isOpen ) {
835
829
const rootNode = this . #tree?. nodes . find ( ( node ) => node . parentId == null ) ;
836
830
const deepestNode =
837
831
this . #tree && rootNode
@@ -879,9 +873,7 @@ class ListNavigationState {
879
873
880
874
// If a floating element should not open on arrow key down, avoid
881
875
// setting `activeIndex` while it's closed.
882
- if ( ! this . context . open && ! this . #openOnArrowKeyDown && isArrowKey ) {
883
- return ;
884
- }
876
+ if ( ! isOpen && ! this . #openOnArrowKeyDown && isArrowKey ) return ;
885
877
886
878
if ( isNavigationKey ) {
887
879
this . #key = this . #nested && isMainKey ? null : event . key ;
@@ -891,7 +883,7 @@ class ListNavigationState {
891
883
if ( isCrossOpenKey ) {
892
884
stopEvent ( event ) ;
893
885
894
- if ( this . context . open ) {
886
+ if ( isOpen ) {
895
887
this . #index = getMinIndex ( this . #listRef, this . #disabledIndices) ;
896
888
this . #onNavigate( ) ;
897
889
} else {
@@ -909,13 +901,13 @@ class ListNavigationState {
909
901
910
902
stopEvent ( event ) ;
911
903
912
- if ( ! this . context . open && this . #openOnArrowKeyDown) {
904
+ if ( ! isOpen && this . #openOnArrowKeyDown) {
913
905
this . context . onOpenChange ( true , event , "list-navigation" ) ;
914
906
} else {
915
907
this . #commonOnKeyDown( event ) ;
916
908
}
917
909
918
- if ( this . context . open ) {
910
+ if ( isOpen ) {
919
911
this . #onNavigate( ) ;
920
912
}
921
913
}
0 commit comments