@@ -460,14 +460,32 @@ function prioritySortRank(priority) {
460460 return 9 ;
461461}
462462
463+ function resetTodoDropdown ( dropdown ) {
464+ dropdown . hidden = true ;
465+ dropdown . style . removeProperty ( 'left' ) ;
466+ dropdown . style . removeProperty ( 'top' ) ;
467+ }
463468function closeTodoMenus ( exceptMenu ) {
464469 document . querySelectorAll ( '[data-task-menu][aria-expanded="true"]' ) . forEach ( ( button ) => {
465470 if ( button === exceptMenu ) return ;
466471 button . setAttribute ( 'aria-expanded' , 'false' ) ;
467472 const dropdown = button . closest ( '.task-actions' ) ?. querySelector ( '.task-menu-dropdown' ) ;
468- if ( dropdown ) dropdown . hidden = true ;
473+ if ( dropdown ) resetTodoDropdown ( dropdown ) ;
469474 } ) ;
470475}
476+ function positionTodoDropdown ( menu , dropdown ) {
477+ const buttonRect = menu . getBoundingClientRect ( ) ;
478+ dropdown . style . position = 'fixed' ;
479+ dropdown . style . left = '0px' ;
480+ dropdown . style . top = '0px' ;
481+ dropdown . hidden = false ;
482+ const dropdownRect = dropdown . getBoundingClientRect ( ) ;
483+ const left = Math . max ( 8 , Math . min ( window . innerWidth - dropdownRect . width - 8 , buttonRect . right - dropdownRect . width ) ) ;
484+ const opensDown = buttonRect . bottom + 6 + dropdownRect . height <= window . innerHeight - 8 ;
485+ const top = opensDown ? Math . min ( window . innerHeight - dropdownRect . height - 8 , buttonRect . bottom + 6 ) : Math . min ( window . innerHeight - dropdownRect . height - 8 , Math . max ( 8 , buttonRect . top - dropdownRect . height - 6 ) ) ;
486+ dropdown . style . left = left + 'px' ;
487+ dropdown . style . top = top + 'px' ;
488+ }
471489function initTodoActions ( ) {
472490 document . addEventListener ( 'click' , ( ev ) => {
473491 const menu = ev . target . closest ( '[data-task-menu]' ) ;
@@ -481,8 +499,11 @@ function initTodoActions() {
481499 const expanded = menu . getAttribute ( 'aria-expanded' ) === 'true' ;
482500 closeTodoMenus ( menu ) ;
483501 menu . setAttribute ( 'aria-expanded' , String ( ! expanded ) ) ;
484- dropdown . hidden = expanded ;
502+ if ( expanded ) resetTodoDropdown ( dropdown ) ;
503+ else positionTodoDropdown ( menu , dropdown ) ;
485504 } ) ;
505+ window . addEventListener ( 'resize' , ( ) => closeTodoMenus ( ) ) ;
506+ window . addEventListener ( 'scroll' , ( ) => closeTodoMenus ( ) , true ) ;
486507 document . addEventListener ( 'keydown' , ( ev ) => {
487508 if ( ev . key === 'Escape' ) closeTodoMenus ( ) ;
488509 } ) ;
0 commit comments