@@ -2800,42 +2800,22 @@ function reset_focus() {
28002800 autofocus . focus ( ) ;
28012801 } else {
28022802 // Reset page selection and focus
2803- if ( location . hash && document . querySelector ( location . hash ) ) {
2804- const { x, y } = scroll_state ( ) ;
2803+ // We try to mimic browsers' behaviour as closely as possible by targeting the
2804+ // first scrollable region, but unfortunately it's not a perfect match — e.g.
2805+ // shift-tabbing won't immediately cycle up from the end of the page on Chromium
2806+ // See https://html.spec.whatwg.org/multipage/interaction.html#get-the-focusable-area
2807+ const root = document . body ;
2808+ const tabindex = root . getAttribute ( 'tabindex' ) ;
2809+
2810+ root . tabIndex = - 1 ;
2811+ // @ts -expect-error
2812+ root . focus ( { preventScroll : true , focusVisible : false } ) ;
28052813
2806- setTimeout ( ( ) => {
2807- const history_state = history . state ;
2808- // Mimic the browsers' behaviour and set the sequential focus navigation
2809- // starting point to the fragment identifier
2810- location . replace ( location . hash ) ;
2811- // but Firefox has a bug that sets the history state as null so we
2812- // need to restore the history state
2813- // See https://bugzilla.mozilla.org/show_bug.cgi?id=1199924
2814- history . replaceState ( history_state , '' , location . hash ) ;
2815-
2816- // Scroll management has already happened earlier so we need to restore
2817- // the scroll position after setting the sequential focus navigation starting point
2818- scrollTo ( x , y ) ;
2819- } ) ;
2814+ // restore `tabindex` as to prevent `root` from stealing input from elements
2815+ if ( tabindex !== null ) {
2816+ root . setAttribute ( 'tabindex' , tabindex ) ;
28202817 } else {
2821- // We try to mimic browsers' behaviour as closely as possible by targeting the
2822- // first scrollable region, but unfortunately it's not a perfect match — e.g.
2823- // shift-tabbing won't immediately cycle up from the end of the page on Chromium
2824- // See https://html.spec.whatwg.org/multipage/interaction.html#get-the-focusable-area
2825- const root = document . body ;
2826- const tabindex = root . getAttribute ( 'tabindex' ) ;
2827-
2828- root . tabIndex = - 1 ;
2829- // @ts -expect-error options.focusVisible is only supported in Firefox
2830- // See https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/focus#browser_compatibility
2831- root . focus ( { preventScroll : true , focusVisible : false } ) ;
2832-
2833- // restore `tabindex` as to prevent `root` from stealing input from elements
2834- if ( tabindex !== null ) {
2835- root . setAttribute ( 'tabindex' , tabindex ) ;
2836- } else {
2837- root . removeAttribute ( 'tabindex' ) ;
2838- }
2818+ root . removeAttribute ( 'tabindex' ) ;
28392819 }
28402820
28412821 // capture current selection, so we can compare the state after
0 commit comments