Skip to content

Commit b4c4a20

Browse files
umegbewecasibbald
andauthored
fix(ui): replace deprecated innerRef prop with React.forwardRef (weaveworks#5312)
Signed-off-by: Umegbewe Nwebedu <nwebedujunior55@gmail.com> Co-authored-by: Charles Sibbald <123247+casibbald@users.noreply.github.com>
1 parent f2fc6b0 commit b4c4a20

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

ui/components/Link.tsx

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Text, { TextProps } from "./Text";
99
type Props = {
1010
className?: string;
1111
to?: string;
12-
innerRef?: any;
1312
children?: any;
1413
href?: any;
1514
target?: any;
@@ -28,19 +27,22 @@ const SpacedIcon = ({ icon }: { icon: JSX.Element }) => (
2827
</>
2928
);
3029

31-
function Link({
32-
children,
33-
href,
34-
className,
35-
to = "",
36-
newTab,
37-
onClick,
38-
textProps,
39-
icon,
40-
onMouseEnter,
41-
onMouseLeave,
42-
...props
43-
}: Props) {
30+
const Link = React.forwardRef<HTMLAnchorElement, Props>(function Link(
31+
{
32+
children,
33+
href,
34+
className,
35+
to = "",
36+
newTab,
37+
onClick,
38+
textProps,
39+
icon,
40+
onMouseEnter,
41+
onMouseLeave,
42+
...props
43+
},
44+
ref
45+
) {
4446
if ((href && !isAllowedLink(href)) || (!href && !to)) {
4547
return (
4648
<Text className={className} {...textProps}>
@@ -58,6 +60,7 @@ function Link({
5860
if (href) {
5961
return (
6062
<a
63+
ref={ref}
6164
className={className}
6265
href={href}
6366
target={newTab ? "_blank" : ""}
@@ -77,6 +80,7 @@ function Link({
7780

7881
return (
7982
<RouterLink
83+
ref={ref}
8084
onClick={onClick}
8185
className={className}
8286
to={to}
@@ -89,8 +93,10 @@ function Link({
8993
{txt}
9094
</RouterLink>
9195
);
92-
}
96+
});
9397

94-
export default styled(Link).attrs({ className: Link.name })`
98+
Link.displayName = "Link";
99+
100+
export default styled(Link).attrs({ className: Link.displayName })`
95101
text-decoration: none;
96102
`;

ui/components/Nav.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ const LinkTabIcon = ({ iconType, color, collapsed, title }) => {
130130
else return <Spacer padding="small" />;
131131
};
132132

133-
const LinkTab = React.forwardRef((p: any, ref) => {
133+
const LinkTab = React.forwardRef<HTMLAnchorElement, any>((p, ref) => {
134134
const [hovered, setHovered] = React.useState<boolean>(false);
135135
const item: NavItem = p.navItem;
136136

@@ -147,7 +147,7 @@ const LinkTab = React.forwardRef((p: any, ref) => {
147147
return (
148148
<Link
149149
className={className}
150-
innerRef={ref}
150+
ref={ref}
151151
to={formatURL(item.link.value)}
152152
href={item.link.href}
153153
newTab={item.link.newTab}

ui/components/SubRouterTabs.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ type TabProps = {
2424

2525
type PathConfig = { name: string; path: string };
2626

27-
const ForwardedLink = React.forwardRef((props, ref) => (
28-
<Link {...props} innerRef={ref} />
27+
const ForwardedLink = React.forwardRef<HTMLAnchorElement>((props, ref) => (
28+
<Link {...props} ref={ref} />
2929
));
3030

3131
function findChildren(childrenProp: any[]) {

0 commit comments

Comments
 (0)