@@ -29,57 +29,63 @@ function isExternalLink(external_link, href) {
2929 return external_link ;
3030}
3131
32- function Link ( {
33- children,
34- preOnClick,
35- target,
36- linkTarget,
37- href,
38- download,
39- external_link,
40- disabled,
41- ...otherProps
42- } ) {
43- const updateLocation = e => {
44- const hasModifiers = e . metaKey || e . shiftKey || e . altKey || e . ctrlKey ;
45- if ( hasModifiers ) {
46- return ;
47- }
48- if ( disabled ) {
49- e . preventDefault ( ) ;
50- return ;
51- }
52- if ( preOnClick ) {
53- preOnClick ( ) ;
54- }
55- if ( href && ! isExternalLink ( external_link , href ) ) {
56- // prevent anchor from updating location
57- e . preventDefault ( ) ;
58- window . history . pushState ( { } , '' , href ) ;
59- window . dispatchEvent ( new CustomEvent ( '_dashprivate_pushstate' ) ) ;
60- // scroll back to top
61- window . scrollTo ( 0 , 0 ) ;
62- }
63- } ;
64-
65- const linkIsExternal = href && isExternalLink ( external_link , href ) ;
66- /**
67- * ideally, we would use cloneElement however
68- * that doesn't work with dash's recursive
69- * renderTree implementation for some reason
70- */
71- return (
72- < a
73- href = { href }
74- target = { linkIsExternal ? target || linkTarget : undefined }
75- download = { download && linkIsExternal ? download : undefined }
76- { ...otherProps }
77- onClick = { e => updateLocation ( e ) }
78- >
79- { children }
80- </ a >
81- ) ;
82- }
32+ const Link = React . forwardRef (
33+ (
34+ {
35+ children,
36+ preOnClick,
37+ target,
38+ linkTarget,
39+ href,
40+ download,
41+ external_link,
42+ disabled,
43+ ...otherProps
44+ } ,
45+ ref
46+ ) => {
47+ const updateLocation = e => {
48+ const hasModifiers = e . metaKey || e . shiftKey || e . altKey || e . ctrlKey ;
49+ if ( hasModifiers ) {
50+ return ;
51+ }
52+ if ( disabled ) {
53+ e . preventDefault ( ) ;
54+ return ;
55+ }
56+ if ( preOnClick ) {
57+ preOnClick ( ) ;
58+ }
59+ if ( href && ! isExternalLink ( external_link , href ) ) {
60+ // prevent anchor from updating location
61+ e . preventDefault ( ) ;
62+ window . history . pushState ( { } , '' , href ) ;
63+ window . dispatchEvent ( new CustomEvent ( '_dashprivate_pushstate' ) ) ;
64+ // scroll back to top
65+ window . scrollTo ( 0 , 0 ) ;
66+ }
67+ } ;
68+
69+ const linkIsExternal = href && isExternalLink ( external_link , href ) ;
70+ /**
71+ * ideally, we would use cloneElement however
72+ * that doesn't work with dash's recursive
73+ * renderTree implementation for some reason
74+ */
75+ return (
76+ < a
77+ href = { href }
78+ target = { linkIsExternal ? target || linkTarget : undefined }
79+ download = { download && linkIsExternal ? download : undefined }
80+ { ...otherProps }
81+ onClick = { e => updateLocation ( e ) }
82+ ref = { ref }
83+ >
84+ { children }
85+ </ a >
86+ ) ;
87+ }
88+ ) ;
8389
8490Link . propTypes = {
8591 /**
0 commit comments