Skip to content

Commit

Permalink
fix(v2): restore previous scroll position on back button click (#5081)
Browse files Browse the repository at this point in the history
  • Loading branch information
lex111 authored Jun 29, 2021
1 parent 7592982 commit 7fe2a98
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

import React, {useRef} from 'react';
import {useHistory} from '@docusaurus/router';
import Translate from '@docusaurus/Translate';
import {useLocationChange} from '@docusaurus/theme-common';

Expand All @@ -19,6 +20,7 @@ function programmaticFocus(el: HTMLElement) {

function SkipToContent(): JSX.Element {
const containerRef = useRef<HTMLDivElement>(null);
const {action} = useHistory();
const handleSkip = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();

Expand All @@ -32,7 +34,7 @@ function SkipToContent(): JSX.Element {
};

useLocationChange(({location}) => {
if (containerRef.current && !location.hash) {
if (containerRef.current && !location.hash && action !== 'POP') {
programmaticFocus(containerRef.current);
}
});
Expand Down

0 comments on commit 7fe2a98

Please sign in to comment.