You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/SafeAnchor.js
+35-44
Original file line number
Diff line number
Diff line change
@@ -15,9 +15,6 @@ const propTypes = {
15
15
* this is sort of silly but needed for Button
16
16
*/
17
17
as: PropTypes.elementType,
18
-
19
-
/** @private */
20
-
innerRef: PropTypes.any,
21
18
};
22
19
23
20
functionisTrivialHref(href){
@@ -31,47 +28,40 @@ function isTrivialHref(href) {
31
28
* button its accessible. It also emulates input `disabled` behavior for
32
29
* links, which is usually desirable for Buttons, NavItems, DropdownItems, etc.
33
30
*/
34
-
classSafeAnchorextendsReact.Component{
35
-
constructor(props,context){
36
-
super(props,context);
37
-
38
-
this.handleClick=this.handleClick.bind(this);
39
-
this.handleKeyDown=this.handleKeyDown.bind(this);
40
-
}
41
-
42
-
handleClick(event){
43
-
const{ disabled, href, onClick }=this.props;
44
-
45
-
if(disabled||isTrivialHref(href)){
46
-
event.preventDefault();
47
-
}
48
-
49
-
if(disabled){
50
-
event.stopPropagation();
51
-
return;
52
-
}
53
-
54
-
if(onClick){
55
-
onClick(event);
56
-
}
57
-
}
58
-
59
-
handleKeyDown(event){
60
-
if(event.key===' '){
61
-
event.preventDefault();
62
-
this.handleClick(event);
63
-
}
64
-
}
65
-
66
-
render(){
67
-
const{
31
+
constSafeAnchor=React.forwardRef(
32
+
(
33
+
{
68
34
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
69
35
as: Component='a',
70
36
disabled,
71
37
onKeyDown,
72
-
innerRef,
73
38
...props
74
-
}=this.props;
39
+
},
40
+
ref,
41
+
)=>{
42
+
consthandleClick=event=>{
43
+
const{ href, onClick }=props;
44
+
45
+
if(disabled||isTrivialHref(href)){
46
+
event.preventDefault();
47
+
}
48
+
49
+
if(disabled){
50
+
event.stopPropagation();
51
+
return;
52
+
}
53
+
54
+
if(onClick){
55
+
onClick(event);
56
+
}
57
+
};
58
+
59
+
consthandleKeyDown=event=>{
60
+
if(event.key===' '){
61
+
event.preventDefault();
62
+
handleClick(event);
63
+
}
64
+
};
75
65
76
66
if(isTrivialHref(props.href)){
77
67
props.role=props.role||'button';
@@ -84,16 +74,17 @@ class SafeAnchor extends React.Component {
0 commit comments