mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-30 06:50:36 +02:00
fix(v2): restore previous scroll position on back button click (#5081)
This commit is contained in:
parent
7592982960
commit
7fe2a9891d
1 changed files with 3 additions and 1 deletions
|
@ -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';
|
||||
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue