Skip to content

Commit 750d89d

Browse files
author
Russell Anderson
authored
fix: rollback ref on unstyled link (#864)
* fix: rollback ref on unstyled link Consuming LinkComponent has been a challenge downstream. We don't actually need the focus style manager to handle unstyled links as far as I can tell, so the console warnings should be resolved without having to keep drilling down into child Link components. * test: update pagination snap
1 parent 7536f5d commit 750d89d

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

packages/button/components/ButtonBase.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ const ButtonContent = ({ iconStart, iconEnd, isProcessing, children }) => {
125125
);
126126
};
127127

128-
const ButtonNode = React.forwardRef(
128+
const ButtonNode = React.forwardRef<HTMLButtonElement, ButtonBaseProps>(
129129
(
130130
{
131131
appearance,
@@ -178,7 +178,6 @@ const ButtonNode = React.forwardRef(
178178
onClick={handleClick}
179179
tabIndex={enabled ? 0 : -1}
180180
openInNewTab={openInNewTab}
181-
ref={ref}
182181
{...other}
183182
>
184183
<ButtonContent
@@ -199,7 +198,7 @@ const ButtonNode = React.forwardRef(
199198
onClick={handleClick}
200199
tabIndex={0}
201200
type={type}
202-
ref={ref as React.ForwardedRef<HTMLButtonElement>}
201+
ref={ref}
203202
aria-haspopup={ariaHaspopup}
204203
aria-label={ariaLabel}
205204
{...other}

packages/link/components/UnstyledLink.tsx

+4-10
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,23 @@ import React from "react";
22
import { LinkComponentContext } from "../../uiKitProvider/link/context";
33
import { ExpandedLinkProps } from "../types";
44

5-
const UnstyledLink = (props: ExpandedLinkProps, ref) => {
5+
const UnstyledLink = (props: ExpandedLinkProps) => {
66
const { href, url, target, openInNewTab, children, ...rest } = props;
77

88
// Context is used for `UIKitProvider` link delegation
99
const LinkComponent = React.useContext(LinkComponentContext);
1010
if (LinkComponent) {
11-
return <LinkComponent ref={ref} {...props} />;
11+
return <LinkComponent {...props} />;
1212
}
1313

1414
const rel = target === "_blank" || openInNewTab ? "noopener" : undefined;
1515
const blankTargetOrDefault = !target && openInNewTab ? "_blank" : target;
1616

1717
return (
18-
<a
19-
ref={ref}
20-
href={href || url}
21-
target={blankTargetOrDefault}
22-
rel={rel}
23-
{...rest}
24-
>
18+
<a href={href || url} target={blankTargetOrDefault} rel={rel} {...rest}>
2519
{children}
2620
</a>
2721
);
2822
};
2923

30-
export default React.forwardRef(UnstyledLink);
24+
export default UnstyledLink;

packages/link/types.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,4 @@ export interface LinkProps {
1515
export type ExpandedLinkProps = LinkProps &
1616
Omit<React.HTMLProps<HTMLAnchorElement>, "ref">;
1717

18-
export type LinkComponent = React.ComponentType<
19-
LinkProps & React.HTMLProps<HTMLAnchorElement>
20-
>;
18+
export type LinkComponent = React.ComponentType<ExpandedLinkProps>;

packages/pagination/__snapshots__/pagination.test.tsx.snap

+8
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ exports[`Pagination rendering renders default 1`] = `
335335
class="emotion-8"
336336
data-cy="textInput-label"
337337
for="textInput-2"
338+
hidden=""
338339
/>
339340
<div>
340341
<div
@@ -701,6 +702,7 @@ exports[`Pagination rendering renders prev and next buttons as links 1`] = `
701702
class="emotion-8"
702703
data-cy="textInput-label"
703704
for="textInput-17"
705+
hidden=""
704706
/>
705707
<div>
706708
<div
@@ -1091,6 +1093,7 @@ exports[`Pagination rendering renders w/ custom item label 1`] = `
10911093
class="emotion-8"
10921094
data-cy="textInput-label"
10931095
for="textInput-8"
1096+
hidden=""
10941097
/>
10951098
<div>
10961099
<div
@@ -1615,6 +1618,7 @@ exports[`Pagination rendering renders w/ page length menu 1`] = `
16151618
class="emotion-4"
16161619
data-cy="textInput-label"
16171620
for="pageLengthMenu19"
1621+
hidden=""
16181622
>
16191623
Items per page
16201624
</label>
@@ -1725,6 +1729,7 @@ exports[`Pagination rendering renders w/ page length menu 1`] = `
17251729
class="emotion-4"
17261730
data-cy="textInput-label"
17271731
for="textInput-20"
1732+
hidden=""
17281733
/>
17291734
<div>
17301735
<div
@@ -2118,6 +2123,7 @@ exports[`Pagination rendering renders w/ totalItems set 1`] = `
21182123
class="emotion-8"
21192124
data-cy="textInput-label"
21202125
for="textInput-11"
2126+
hidden=""
21212127
/>
21222128
<div>
21232129
<div
@@ -2513,6 +2519,7 @@ exports[`Pagination rendering renders w/ totalPages, pageLength, and totalItems
25132519
class="emotion-8"
25142520
data-cy="textInput-label"
25152521
for="textInput-14"
2522+
hidden=""
25162523
/>
25172524
<div>
25182525
<div
@@ -2958,6 +2965,7 @@ exports[`Pagination rendering renders wrapped in a PaginationContainer 1`] = `
29582965
class="emotion-10"
29592966
data-cy="textInput-label"
29602967
for="textInput-5"
2968+
hidden=""
29612969
/>
29622970
<div>
29632971
<div

0 commit comments

Comments
 (0)