@@ -614,16 +614,21 @@ class AppSidebar extends LitElement {
614614 }
615615 }
616616
617- private openSessionSortMenu ( x : number , y : number , trigger : HTMLElement | null = null ) {
617+ private toggleSessionSortMenu ( trigger : HTMLElement ) {
618+ if ( this . sessionSortMenuPosition ) {
619+ this . closeSessionSortMenu ( ) ;
620+ return ;
621+ }
618622 const menuWidth = 200 ;
619623 const menuMaxHeight = 280 ;
624+ const rect = trigger . getBoundingClientRect ( ) ;
620625 this . closeCustomizeMenu ( ) ;
621626 this . closeSessionMenu ( ) ;
622627 this . closeSessionGroupMenu ( ) ;
623628 this . sessionSortMenuTrigger = trigger ;
624629 this . sessionSortMenuPosition = {
625- x : Math . max ( 8 , Math . min ( x , window . innerWidth - menuWidth - 8 ) ) ,
626- y : Math . max ( 8 , Math . min ( y , window . innerHeight - menuMaxHeight - 8 ) ) ,
630+ x : Math . max ( 8 , Math . min ( rect . right , window . innerWidth - menuWidth - 8 ) ) ,
631+ y : Math . max ( 8 , Math . min ( rect . bottom + 4 , window . innerHeight - menuMaxHeight - 8 ) ) ,
627632 } ;
628633 document . addEventListener ( "pointerdown" , this . handleDocumentPointerDown , true ) ;
629634 document . addEventListener ( "keydown" , this . handleDocumentKeydown , true ) ;
@@ -764,6 +769,9 @@ class AppSidebar extends LitElement {
764769
765770 private readonly handleDocumentPointerDown = ( event : PointerEvent ) => {
766771 const path = event . composedPath ( ) ;
772+ if ( this . sessionSortMenuTrigger && path . includes ( this . sessionSortMenuTrigger ) ) {
773+ return ;
774+ }
767775 const menu = this . querySelector (
768776 ".sidebar-customize-menu, .sidebar-session-menu, .sidebar-session-sort-menu" ,
769777 ) ;
@@ -1496,8 +1504,7 @@ class AppSidebar extends LitElement {
14961504 aria-expanded=${ String ( this . sessionSortMenuPosition !== null ) }
14971505 @click=${ ( event : MouseEvent ) => {
14981506 const trigger = event . currentTarget as HTMLElement ;
1499- const rect = trigger . getBoundingClientRect ( ) ;
1500- this . openSessionSortMenu ( rect . right , rect . bottom + 4 , trigger ) ;
1507+ this . toggleSessionSortMenu ( trigger ) ;
15011508 } }
15021509 >
15031510 ${ icons . listFilter }
0 commit comments