Skip to content

Commit 70e8ed0

Browse files
authored
[docs] Fix element.ref accessing warning on docs (#45155)
1 parent 7d816ce commit 70e8ed0

File tree

3 files changed

+13
-64
lines changed
  • examples
    • material-ui-nextjs-pages-router-ts/src
    • material-ui-nextjs-pages-router/src

3 files changed

+13
-64
lines changed

examples/material-ui-nextjs-pages-router-ts/src/Link.tsx

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@ import clsx from 'clsx';
33
import { useRouter } from 'next/router';
44
import NextLink, { LinkProps as NextLinkProps } from 'next/link';
55
import MuiLink, { LinkProps as MuiLinkProps } from '@mui/material/Link';
6-
import { styled } from '@mui/material/styles';
7-
8-
// Add support for the sx prop for consistency with the other branches.
9-
const Anchor = styled('a')({});
106

117
interface NextLinkComposedProps
128
extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>,
@@ -17,17 +13,7 @@ interface NextLinkComposedProps
1713

1814
export const NextLinkComposed = React.forwardRef<HTMLAnchorElement, NextLinkComposedProps>(
1915
function NextLinkComposed(props, ref) {
20-
const {
21-
to,
22-
linkAs,
23-
replace,
24-
scroll,
25-
shallow,
26-
prefetch,
27-
legacyBehavior = true,
28-
locale,
29-
...other
30-
} = props;
16+
const { to, linkAs, replace, scroll, shallow, prefetch, locale, ...other } = props;
3117

3218
return (
3319
<NextLink
@@ -39,10 +25,9 @@ export const NextLinkComposed = React.forwardRef<HTMLAnchorElement, NextLinkComp
3925
shallow={shallow}
4026
passHref
4127
locale={locale}
42-
legacyBehavior={legacyBehavior}
43-
>
44-
<Anchor ref={ref} {...other} />
45-
</NextLink>
28+
ref={ref}
29+
{...other}
30+
/>
4631
);
4732
},
4833
);
@@ -64,7 +49,6 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
6449
as,
6550
className: classNameProps,
6651
href,
67-
legacyBehavior,
6852
linkAs: linkAsProp,
6953
locale,
7054
noLinkStyle,
@@ -90,7 +74,6 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
9074
scroll,
9175
shallow,
9276
prefetch,
93-
legacyBehavior,
9477
locale,
9578
};
9679

examples/material-ui-nextjs-pages-router/src/Link.js

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,9 @@ import clsx from 'clsx';
33
import { useRouter } from 'next/router';
44
import NextLink from 'next/link';
55
import MuiLink from '@mui/material/Link';
6-
import { styled } from '@mui/material/styles';
7-
8-
// Add support for the sx prop for consistency with the other branches.
9-
const Anchor = styled('a')({});
106

117
export const NextLinkComposed = React.forwardRef(function NextLinkComposed(props, ref) {
12-
const {
13-
to,
14-
linkAs,
15-
replace,
16-
scroll,
17-
shallow,
18-
prefetch,
19-
legacyBehavior = true,
20-
locale,
21-
...other
22-
} = props;
8+
const { to, linkAs, replace, scroll, shallow, prefetch, locale, ...other } = props;
239

2410
return (
2511
<NextLink
@@ -30,11 +16,10 @@ export const NextLinkComposed = React.forwardRef(function NextLinkComposed(props
3016
scroll={scroll}
3117
shallow={shallow}
3218
passHref
33-
legacyBehavior={legacyBehavior}
3419
locale={locale}
35-
>
36-
<Anchor ref={ref} {...other} />
37-
</NextLink>
20+
ref={ref}
21+
{...other}
22+
/>
3823
);
3924
});
4025

@@ -46,7 +31,6 @@ const Link = React.forwardRef(function Link(props, ref) {
4631
as,
4732
className: classNameProps,
4833
href,
49-
legacyBehavior,
5034
linkAs: linkAsProp,
5135
locale,
5236
noLinkStyle,
@@ -72,7 +56,6 @@ const Link = React.forwardRef(function Link(props, ref) {
7256
scroll,
7357
shallow,
7458
prefetch,
75-
legacyBehavior,
7659
locale,
7760
};
7861

packages/mui-docs/src/Link/Link.tsx

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,16 @@ import clsx from 'clsx';
33
import { useRouter } from 'next/router';
44
import NextLink, { LinkProps as NextLinkProps } from 'next/link';
55
import MuiLink, { LinkProps as MuiLinkProps } from '@mui/material/Link';
6-
import { styled } from '@mui/material/styles';
76
import { useUserLanguage } from '../i18n';
87
import { useDocsConfig } from '../DocsProvider';
98

109
/**
1110
* File to keep in sync with:
1211
*
13-
* - /docs/src/modules/components/Link.tsx
1412
* - /examples/material-ui-nextjs-pages-router/src/Link.js
1513
* - /examples/material-ui-nextjs-pages-router-ts/src/Link.tsx
1614
*/
1715

18-
// Add support for the sx prop for consistency with the other branches.
19-
const Anchor = styled('a')({});
20-
2116
interface NextLinkComposedProps
2217
extends Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href'>,
2318
Omit<NextLinkProps, 'href' | 'as' | 'passHref' | 'onMouseEnter' | 'onClick' | 'onTouchStart'> {
@@ -27,17 +22,7 @@ interface NextLinkComposedProps
2722

2823
const NextLinkComposed = React.forwardRef<HTMLAnchorElement, NextLinkComposedProps>(
2924
function NextLinkComposed(props, ref) {
30-
const {
31-
to,
32-
linkAs,
33-
replace,
34-
scroll,
35-
shallow,
36-
prefetch,
37-
legacyBehavior = true,
38-
locale,
39-
...other
40-
} = props;
25+
const { to, linkAs, replace, scroll, shallow, prefetch, locale, ...other } = props;
4126

4227
return (
4328
<NextLink
@@ -49,10 +34,10 @@ const NextLinkComposed = React.forwardRef<HTMLAnchorElement, NextLinkComposedPro
4934
shallow={shallow}
5035
passHref
5136
locale={locale}
52-
legacyBehavior={legacyBehavior}
53-
>
54-
<Anchor data-no-markdown-link="true" ref={ref} {...other} />
55-
</NextLink>
37+
data-no-markdown-link="true"
38+
ref={ref}
39+
{...other}
40+
/>
5641
);
5742
},
5843
);
@@ -74,7 +59,6 @@ export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link
7459
as,
7560
className: classNameProps,
7661
href,
77-
legacyBehavior,
7862
linkAs: linkAsProp,
7963
locale,
8064
noLinkStyle,
@@ -116,7 +100,6 @@ export const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link
116100
replace,
117101
scroll,
118102
shallow,
119-
legacyBehavior,
120103
prefetch,
121104
locale,
122105
};

0 commit comments

Comments
 (0)