File tree Expand file tree Collapse file tree
src/pydata_sphinx_theme/assets/scripts Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -836,11 +836,25 @@ function setupMobileSidebarKeyboardHandlers() {
836836 event . preventDefault ( ) ;
837837 event . stopPropagation ( ) ;
838838
839+ // Save focus so we can restore it when the dialog closes
840+ const previouslyFocused = document . activeElement ;
841+
839842 // When we open the dialog, we cut and paste the nodes and classes from
840843 // the widescreen sidebar into the dialog
841844 cutAndPasteNodesAndClasses ( sidebar , dialog ) ;
842845
843846 dialog . showModal ( ) ;
847+
848+ // Restore focus when dialog closes
849+ dialog . addEventListener (
850+ "close" ,
851+ ( ) => {
852+ if ( previouslyFocused && previouslyFocused . focus ) {
853+ previouslyFocused . focus ( ) ;
854+ }
855+ } ,
856+ { once : true } ,
857+ ) ;
844858 } ) ;
845859
846860 // Listen for clicks on the backdrop in order to close the dialog
You can’t perform that action at this time.
0 commit comments