@@ -221,6 +221,7 @@ class ListNavigationState {
221221 #parentId: string | null = null ;
222222 #tree: FloatingTreeType | null = null ;
223223 #index = $state ( this . #selectedIndex ?? - 1 ) ;
224+
224225 #typeableComboboxReference = $derived . by ( ( ) =>
225226 isTypeableCombobox ( this . context . domReference ) ,
226227 ) ;
@@ -232,9 +233,8 @@ class ListNavigationState {
232233
233234 #activeId = $state < string | undefined > ( ) ;
234235 #virtualId = $state < string | undefined > ( ) ;
235- #previousMounted: boolean ;
236- #previousOpen: boolean ;
237- #previousOnNavigate: ( ) => void ;
236+ #mounted = false ;
237+ #previousOpen = false ;
238238 #hasActiveIndex = $derived . by ( ( ) => this . #activeIndex != null ) ;
239239
240240 #ariaActiveDescendantProp = $derived . by ( ( ) => {
@@ -273,9 +273,7 @@ class ListNavigationState {
273273 this . #virtualItemRef = this . opts . virtualItemRef ;
274274 this . #parentId = useFloatingParentNodeId ( ) ;
275275 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 ;
279277
280278 // Sync `selectedIndex` to be the `activeIndex` upon opening the floating
281279 // element. Also, reset `activeIndex` upon closing the floating element.
@@ -296,7 +294,7 @@ class ListNavigationState {
296294 this . #index = this . #selectedIndex;
297295 this . #onNavigate( ) ;
298296 }
299- } else if ( this . #previousMounted ) {
297+ } else if ( this . #mounted ) {
300298 this . #index = - 1 ;
301299 this . #onNavigate( ) ;
302300 }
@@ -331,14 +329,14 @@ class ListNavigationState {
331329 }
332330
333331 // Reset while the floating element was open (e.g. the list changed).
334- if ( this . #previousMounted ) {
332+ if ( this . #mounted ) {
335333 this . #index = - 1 ;
336334 this . #focusItem( ) ;
337335 }
338336
339337 // Initial sync.
340338 if (
341- ( ! this . #previousOpen || ! this . #previousMounted ) &&
339+ ( ! this . #previousOpen || ! this . #mounted ) &&
342340 this . #focusItemOnOpen &&
343341 ( this . #key != null ||
344342 ( this . #focusItemOnOpen === true && this . #key == null ) )
@@ -397,7 +395,7 @@ class ListNavigationState {
397395 this . context . floating ||
398396 ! this . #tree ||
399397 this . #virtual ||
400- ! this . #previousMounted
398+ ! this . #mounted
401399 ) {
402400 return ;
403401 }
@@ -446,17 +444,13 @@ class ListNavigationState {
446444 ) ;
447445
448446 $effect . pre ( ( ) => {
449- this . #previousMounted = ! ! this . context . floating ;
447+ this . #mounted = ! ! this . context . floating ;
450448 } ) ;
451449
452450 $effect . pre ( ( ) => {
453451 this . #previousOpen = this . context . open ;
454452 } ) ;
455453
456- $effect . pre ( ( ) => {
457- this . #previousOnNavigate = this . #onNavigate;
458- } ) ;
459-
460454 $effect . pre ( ( ) => {
461455 this . #focusItemOnOpen = this . #focusItemOnOpenProp;
462456 } ) ;
@@ -472,7 +466,6 @@ class ListNavigationState {
472466 }
473467
474468 #onNavigate = ( ) => {
475- console . log ( "calling on navigate" ) ;
476469 this . opts . onNavigate ?.( this . #index === - 1 ? null : this . #index) ;
477470 } ;
478471
@@ -811,6 +804,7 @@ class ListNavigationState {
811804
812805 #referenceOnKeyDown = ( event : KeyboardEvent ) => {
813806 this . #isPointerModality = false ;
807+ const isOpen = this . context . open ;
814808
815809 const isArrowKey = event . key . startsWith ( "Arrow" ) ;
816810 const isHomeOrEndKey = [ "Home" , "End" ] . includes ( event . key ) ;
@@ -831,7 +825,7 @@ class ListNavigationState {
831825 event . key === "Enter" ||
832826 event . key . trim ( ) === "" ;
833827
834- if ( this . #virtual && this . context . open ) {
828+ if ( this . #virtual && isOpen ) {
835829 const rootNode = this . #tree?. nodes . find ( ( node ) => node . parentId == null ) ;
836830 const deepestNode =
837831 this . #tree && rootNode
@@ -879,9 +873,7 @@ class ListNavigationState {
879873
880874 // If a floating element should not open on arrow key down, avoid
881875 // setting `activeIndex` while it's closed.
882- if ( ! this . context . open && ! this . #openOnArrowKeyDown && isArrowKey ) {
883- return ;
884- }
876+ if ( ! isOpen && ! this . #openOnArrowKeyDown && isArrowKey ) return ;
885877
886878 if ( isNavigationKey ) {
887879 this . #key = this . #nested && isMainKey ? null : event . key ;
@@ -891,7 +883,7 @@ class ListNavigationState {
891883 if ( isCrossOpenKey ) {
892884 stopEvent ( event ) ;
893885
894- if ( this . context . open ) {
886+ if ( isOpen ) {
895887 this . #index = getMinIndex ( this . #listRef, this . #disabledIndices) ;
896888 this . #onNavigate( ) ;
897889 } else {
@@ -909,13 +901,13 @@ class ListNavigationState {
909901
910902 stopEvent ( event ) ;
911903
912- if ( ! this . context . open && this . #openOnArrowKeyDown) {
904+ if ( ! isOpen && this . #openOnArrowKeyDown) {
913905 this . context . onOpenChange ( true , event , "list-navigation" ) ;
914906 } else {
915907 this . #commonOnKeyDown( event ) ;
916908 }
917909
918- if ( this . context . open ) {
910+ if ( isOpen ) {
919911 this . #onNavigate( ) ;
920912 }
921913 }
0 commit comments