@@ -231,6 +231,71 @@ window.onload = function() {
231231
232232} ;
233233
234+ // Ensure focus returns to main content after sidebar toggle to keep scroll behavior responsive
235+ function addFocusRestoreAfterSidebarToggle ( ) {
236+ function getMainContent ( ) {
237+ return (
238+ document . getElementById ( 'documenter-page' ) ||
239+ document . querySelector ( '#documenter .docs-main article.content' ) ||
240+ document . querySelector ( '#documenter article.content' ) ||
241+ document . querySelector ( 'article.content' )
242+ ) ;
243+ }
244+
245+ function ensureMainTabindex ( ) {
246+ var main = getMainContent ( ) ;
247+ if ( main && ! main . hasAttribute ( 'tabindex' ) ) {
248+ main . setAttribute ( 'tabindex' , '-1' ) ;
249+ }
250+ return main ;
251+ }
252+
253+ function focusMainContent ( ) {
254+ var main = ensureMainTabindex ( ) ;
255+ if ( main ) {
256+ try { main . focus ( { preventScroll : true } ) ; } catch ( e ) { try { main . focus ( ) ; } catch ( e2 ) { } }
257+ } else {
258+ try { window . focus ( ) ; } catch ( e ) { }
259+ }
260+ }
261+
262+ function blurSidebarToggle ( ) {
263+ var btn = document . getElementById ( 'documenter-sidebar-button' ) ;
264+ if ( btn && typeof btn . blur === 'function' ) {
265+ try { btn . blur ( ) ; } catch ( e ) { }
266+ }
267+ }
268+
269+ function onToggleAttempt ( e ) {
270+ var el = e . target ;
271+ if ( ! el ) return ;
272+ var isToggle = ( el . id === 'documenter-sidebar-button' ) || ( el . closest && el . closest ( '#documenter-sidebar-button' ) ) ;
273+ if ( ! isToggle ) return ;
274+ // Immediately blur the toggle to release focus
275+ blurSidebarToggle ( ) ;
276+ // Restore focus to main content (twice to survive async class toggles)
277+ setTimeout ( focusMainContent , 0 ) ;
278+ setTimeout ( focusMainContent , 60 ) ;
279+ }
280+
281+ // Listeners on multiple interaction types for robustness
282+ document . addEventListener ( 'mousedown' , onToggleAttempt , true ) ;
283+ document . addEventListener ( 'touchstart' , onToggleAttempt , { passive : true , capture : true } ) ;
284+ document . addEventListener ( 'click' , onToggleAttempt , true ) ;
285+
286+ // Ensure tabindex exists early
287+ ensureMainTabindex ( ) ;
288+ }
289+
290+ // Initialize focus restore as soon as possible
291+ try {
292+ if ( document . readyState === 'complete' || document . readyState === 'interactive' ) {
293+ addFocusRestoreAfterSidebarToggle ( ) ;
294+ } else {
295+ document . addEventListener ( 'DOMContentLoaded' , addFocusRestoreAfterSidebarToggle ) ;
296+ }
297+ } catch ( e ) { /* no-op */ }
298+
234299// Add scroll behavior to hide topbar when scrolled down beyond a threshold
235300function addScrollTopBehavior ( ) {
236301 var ticking = false ;
0 commit comments