File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ import React , { PropTypes } from 'react' ;
2
+ import { Link } from 'react-router-dom' ;
3
+
4
+ function hashLinkScroll ( ) {
5
+ // Push onto callback queue so it runs after the DOM is updated
6
+ setTimeout ( ( ) => {
7
+ const { hash } = window . location ;
8
+ if ( hash !== '' ) {
9
+ const id = hash . replace ( '#' , '' ) ;
10
+ const element = document . getElementById ( id ) ;
11
+ if ( element ) element . scrollIntoView ( ) ;
12
+ }
13
+ } , 0 ) ;
14
+ }
15
+
16
+ export function HashLink ( props ) {
17
+ function handleClick ( e ) {
18
+ if ( props . onClick ) props . onClick ( e ) ;
19
+ hashLinkScroll ( ) ;
20
+ }
21
+ return < Link { ...props } onClick = { handleClick } > { props . children } </ Link > ;
22
+ }
23
+
24
+ HashLink . PropTypes = {
25
+ onClick : PropTypes . func ,
26
+ children : PropTypes . node ,
27
+ } ;
You can’t perform that action at this time.
0 commit comments