File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { Link, NavLink } from 'react-router-dom';
5
5
let hashFragment = '' ;
6
6
let observer = null ;
7
7
let asyncTimerId = null ;
8
+ let scrollFunction = null ;
8
9
9
10
function reset ( ) {
10
11
hashFragment = '' ;
@@ -18,7 +19,7 @@ function reset() {
18
19
function getElAndScroll ( ) {
19
20
const element = document . getElementById ( hashFragment ) ;
20
21
if ( element !== null ) {
21
- element . scrollIntoView ( ) ;
22
+ scrollFunction ( element ) ;
22
23
reset ( ) ;
23
24
return true ;
24
25
}
@@ -60,7 +61,13 @@ export function genericHashLink(props, As) {
60
61
) {
61
62
hashFragment = props . to . hash . replace ( '#' , '' ) ;
62
63
}
63
- if ( hashFragment !== '' ) hashLinkScroll ( ) ;
64
+ if ( hashFragment !== '' ) {
65
+ scrollFunction =
66
+ props . scroll ||
67
+ ( el =>
68
+ el . scrollIntoView ( props . smooth ? { behavior : 'smooth' } : undefined ) ) ;
69
+ hashLinkScroll ( ) ;
70
+ }
64
71
}
65
72
return (
66
73
< As { ...props } onClick = { handleClick } >
@@ -80,6 +87,7 @@ export function NavHashLink(props) {
80
87
const propTypes = {
81
88
onClick : PropTypes . func ,
82
89
children : PropTypes . node ,
90
+ scroll : PropTypes . func ,
83
91
to : PropTypes . oneOfType ( [ PropTypes . string , PropTypes . object ] ) ,
84
92
} ;
85
93
You can’t perform that action at this time.
0 commit comments