11import  type  {  RouteLocationNormalized  }  from  './typed-routes' 
22import  {  Router ,  RouterOptions  }  from  './router' 
3+ import  {  nextTick  }  from  'vue' 
34
45export  function  enableFocusManagement ( router : Router )  { 
56  // navigation-api router will handle this for us 
@@ -13,7 +14,7 @@ export function enableFocusManagement(router: Router) {
1314    clearFocusTimeout ( ) 
1415  } ) 
1516
16-   const  unregister  =  router . afterEach ( async  ( to ,   from )  =>  { 
17+   const  unregister  =  router . afterEach ( async  to  =>  { 
1718    const  focusManagement  = 
1819      to . meta . focusManagement  ??  router . options . focusManagement 
1920
@@ -31,6 +32,9 @@ export function enableFocusManagement(router: Router) {
3132      selector  =  focusManagement 
3233    } 
3334
35+     // ensure DOM is updated, enqueuing a microtask before handling focus 
36+     await  nextTick ( ) 
37+ 
3438    handleFocus ( selector ) 
3539  } ) 
3640
@@ -65,6 +69,7 @@ export function prepareFocusReset(
6569
6670export  function  createFocusManagementHandler ( )  { 
6771  let  timeoutId : ReturnType < typeof  setTimeout >  |  undefined 
72+ 
6873  return  { 
6974    handleFocus : ( selector : string )  =>  { 
7075      clearTimeout ( timeoutId ) 
@@ -100,5 +105,5 @@ function handleFocusManagement(
100105    target . focus ( {  preventScroll : true  } ) 
101106    // remove tabindex and event listener if focus still not worked 
102107    if  ( document . activeElement  !==  target )  restoreTabindex ( ) 
103-   } ,  0 ) 
108+   } ,  150 )   // screen readers may need more time to react 
104109} 
0 commit comments