Skip to content

Commit cbfa0e0

Browse files
TheSharpieOneeddywashere
authored andcommitted
feat(refs): add getRef to focusable components (#218)
1 parent 55e47b3 commit cbfa0e0

5 files changed

Lines changed: 19 additions & 9 deletions

File tree

src/Button.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const propTypes = {
99
disabled: PropTypes.bool,
1010
outline: PropTypes.bool,
1111
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
12+
getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
1213
onClick: PropTypes.func,
1314
size: PropTypes.string,
1415
children: PropTypes.node,
@@ -18,7 +19,7 @@ const propTypes = {
1819

1920
const defaultProps = {
2021
color: 'secondary',
21-
tag: 'button'
22+
tag: 'button',
2223
};
2324

2425
class Button extends React.Component {
@@ -49,6 +50,7 @@ class Button extends React.Component {
4950
outline,
5051
size,
5152
tag: Tag,
53+
getRef,
5254
...attributes
5355
} = this.props;
5456

@@ -66,7 +68,7 @@ class Button extends React.Component {
6668
}
6769

6870
return (
69-
<Tag {...attributes} className={classes} onClick={this.onClick} />
71+
<Tag {...attributes} className={classes} ref={getRef} onClick={this.onClick} />
7072
);
7173
}
7274
}

src/CardLink.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { mapToCssModules } from './utils';
44

55
const propTypes = {
66
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
7+
getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
78
className: PropTypes.string,
89
cssModule: PropTypes.object,
910
};
@@ -17,6 +18,7 @@ const CardLink = (props) => {
1718
className,
1819
cssModule,
1920
tag: Tag,
21+
getRef,
2022
...attributes
2123
} = props;
2224
const classes = mapToCssModules(classNames(
@@ -25,7 +27,7 @@ const CardLink = (props) => {
2527
), cssModule);
2628

2729
return (
28-
<Tag {...attributes} className={classes} />
30+
<Tag {...attributes} ref={getRef} className={classes} />
2931
);
3032
};
3133

src/Form.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import { mapToCssModules } from './utils';
55
const propTypes = {
66
children: PropTypes.node,
77
inline: PropTypes.bool,
8-
tag: PropTypes.string,
8+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
9+
getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
910
className: PropTypes.string,
1011
cssModule: PropTypes.object,
1112
};
@@ -20,6 +21,7 @@ const Form = (props) => {
2021
cssModule,
2122
inline,
2223
tag: Tag,
24+
getRef,
2325
...attributes,
2426
} = props;
2527

@@ -29,7 +31,7 @@ const Form = (props) => {
2931
), cssModule);
3032

3133
return (
32-
<Tag {...attributes} className={classes} />
34+
<Tag {...attributes} ref={getRef} className={classes} />
3335
);
3436
};
3537

src/Input.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ const propTypes = {
99
type: PropTypes.string,
1010
size: PropTypes.string,
1111
state: PropTypes.string,
12-
tag: PropTypes.string,
12+
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
13+
getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
1314
static: PropTypes.bool,
1415
addon: PropTypes.bool,
1516
className: PropTypes.string,
@@ -32,6 +33,7 @@ class Input extends React.Component {
3233
tag,
3334
addon,
3435
static: staticInput,
36+
getRef,
3537
...attributes,
3638
} = this.props;
3739

@@ -69,7 +71,7 @@ class Input extends React.Component {
6971
}
7072

7173
return (
72-
<Tag {...attributes} className={classes} />
74+
<Tag {...attributes} ref={getRef} className={classes} />
7375
);
7476
}
7577
}

src/NavLink.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { mapToCssModules } from './utils';
44

55
const propTypes = {
66
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
7+
getRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
78
disabled: PropTypes.bool,
89
active: PropTypes.bool,
910
className: PropTypes.string,
@@ -13,7 +14,7 @@ const propTypes = {
1314
};
1415

1516
const defaultProps = {
16-
tag: 'a'
17+
tag: 'a',
1718
};
1819

1920
class NavLink extends React.Component {
@@ -44,6 +45,7 @@ class NavLink extends React.Component {
4445
cssModule,
4546
active,
4647
tag: Tag,
48+
getRef,
4749
...attributes
4850
} = this.props;
4951

@@ -57,7 +59,7 @@ class NavLink extends React.Component {
5759
), cssModule);
5860

5961
return (
60-
<Tag {...attributes} onClick={this.onClick} className={classes} />
62+
<Tag {...attributes} ref={getRef} onClick={this.onClick} className={classes} />
6163
);
6264
}
6365
}

0 commit comments

Comments
 (0)