Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Fix broken Next and Previous links #29711

Merged
merged 2 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions docs/src/modules/components/AppNavDrawerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,9 @@ const iconsMap = {
ReaderIcon: ChromeReaderModeOutlined,
};

const Item = styled(
function Item({ component: Component = 'div', ...props }) {
return <Component {...props} />;
},
{
// disable `as` prop
shouldForwardProp: () => true,
},
)(({ theme }) => ({
const Item = styled(function Item({ component: Component = 'div', ...props }) {
return <Component {...props} />;
})(({ theme }) => ({
...theme.typography.body2,
display: 'flex',
borderRadius: 5,
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/AppTableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export default function AppTableOfContents(props) {
const itemLink = (item, secondary) => (
<NavItem
display="block"
href={`${activePage.linkProps?.as ?? activePage.pathname}#${item.hash}`}
href={`${activePage.linkProps?.linkAs ?? activePage.pathname}#${item.hash}`}
underline="none"
onClick={handleClick(item.hash)}
active={activeState === item.hash}
Expand Down
12 changes: 7 additions & 5 deletions docs/src/modules/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export type LinkProps = {
activeClassName?: string;
as?: NextLinkProps['as'];
href: NextLinkProps['href'];
linkAs?: NextLinkProps['as']; // Useful when the as prop is shallow by styled().
noLinkStyle?: boolean;
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> &
Omit<MuiLinkProps, 'href'>;
Expand All @@ -60,9 +61,10 @@ export type LinkProps = {
const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props, ref) {
const {
activeClassName = 'active',
as: linkAsProp,
as: asProp,
className: classNameProps,
href,
linkAs: linkAsProp,
noLinkStyle,
role, // Link don't have roles.
...other
Expand All @@ -86,12 +88,12 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
return <MuiLink className={className} href={href} ref={ref} {...other} />;
}

let linkAs = linkAsProp || (href as string);
let linkAs = linkAsProp || asProp || (href as string);
if (
userLanguage !== 'en' &&
typeof href === 'string' &&
href.indexOf('/') === 0 &&
href.indexOf('/blog') !== 0
pathname &&
pathname.indexOf('/') === 0 &&
pathname.indexOf('/blog') !== 0
) {
linkAs = `/${userLanguage}${linkAs}`;
}
Expand Down
10 changes: 8 additions & 2 deletions docs/src/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,15 +226,21 @@ const pages: readonly MuiPage[] = [
title: 'GridPrintExportOptions',
},
].map((page) => {
return { ...page, linkProps: { as: `${page.pathname.replace(/^\/api-docs/, '/api')}/` } };
return {
...page,
linkProps: { linkAs: `${page.pathname.replace(/^\/api-docs/, '/api')}/` },
};
}),
},
]
.sort((a, b) =>
a.pathname.replace('/api-docs/', '').localeCompare(b.pathname.replace('/api-docs/', '')),
)
.map((page) => {
return { ...page, linkProps: { as: `${page.pathname.replace(/^\/api-docs/, '/api')}/` } };
return {
...page,
linkProps: { linkAs: `${page.pathname.replace(/^\/api-docs/, '/api')}/` },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mui-org/x heads up, this is a breaking change, you need to apply the same diff once you upgrade the mono-repo. We improve the support for the translation of the docs.

};
}),
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type LinkProps = {
activeClassName?: string;
as?: NextLinkProps['as'];
href: NextLinkProps['href'];
linkAs?: NextLinkProps['as']; // Useful when the as prop is shallow by styled().
noLinkStyle?: boolean;
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> &
Omit<MuiLinkProps, 'href'>;
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs-with-typescript/src/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export type LinkProps = {
activeClassName?: string;
as?: NextLinkProps['as'];
href: NextLinkProps['href'];
linkAs?: NextLinkProps['as']; // Useful when the as prop is shallow by styled().
noLinkStyle?: boolean;
} & Omit<NextLinkComposedProps, 'to' | 'linkAs' | 'href'> &
Omit<MuiLinkProps, 'href'>;
Expand Down
1 change: 1 addition & 0 deletions examples/nextjs/src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ Link.propTypes = {
as: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
className: PropTypes.string,
href: PropTypes.any,
linkAs: PropTypes.oneOfType([PropTypes.object, PropTypes.string]),
noLinkStyle: PropTypes.bool,
role: PropTypes.string,
};
Expand Down