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-infra] Improve support for absolute locale URL #40940

Merged
merged 1 commit into from
Feb 5, 2024
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
2 changes: 1 addition & 1 deletion docs/pages/blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function PostPreview(props: BlogPost) {
>
<Link
aria-describedby={`describe-${props.slug}`}
href={`/blog/${props.slug}`}
href={`/blog/${props.slug}/`}
sx={{
color: 'text.primary',
'&:hover': {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/AppNavDrawerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ export default function AppNavDrawerItem(props) {
} = props;
const [open, setOpen] = React.useState(initiallyExpanded);
const handleClick = (event) => {
// Ignore the action if opening the link in a new tab
// Ignore click events meant for native link handling, e.g. open in new tab
if (samePageLinkNavigation(event)) {
return;
}
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 @@ -204,7 +204,7 @@ export default function AppTableOfContents(props) {
useThrottledOnScroll(items.length > 0 ? findActiveIndex : null, 166);

const handleClick = (hash) => (event) => {
// Ignore click for new tab/new window behavior
// Ignore click events meant for native link handling, e.g. open in new tab
if (samePageLinkNavigation(event)) {
return;
}
Expand Down
10 changes: 0 additions & 10 deletions docs/src/modules/components/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,8 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
[activeClassName]: shouldBeActive && activeClassName,
});

const isExternal =
typeof href === 'string' && (href.indexOf('http') === 0 || href.indexOf('mailto:') === 0);
const userLanguage = useUserLanguage();

if (isExternal) {
if (noLinkStyle) {
return <Anchor className={className} href={href} ref={ref} {...other} />;
}

return <MuiLink className={className} href={href} ref={ref} {...other} />;
}

let linkAs = linkAsProp || as || (href as string);
if (
userLanguage !== 'en' &&
Expand Down
14 changes: 7 additions & 7 deletions docs/src/modules/components/MarkdownLinks.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ function isLink(event) {
activeElement = activeElement.parentElement;
}

// Ignore non internal link clicks
// Ignore non internal link clicks.
// Absolute URLs can be internal, we delegate this to Next.js's router
if (
activeElement === null ||
activeElement.nodeName !== 'A' ||
activeElement.getAttribute('target') === '_blank' ||
activeElement.getAttribute('data-no-markdown-link') === 'true' ||
activeElement.getAttribute('href').indexOf('/') !== 0
activeElement.getAttribute('data-no-markdown-link') === 'true'
) {
return null;
}
Expand All @@ -40,13 +40,13 @@ function isLink(event) {
* @param {MouseEvent} event
*/
function handleClick(event) {
const activeElement = isLink(event);
if (activeElement === null) {
// Ignore click events meant for native link handling, e.g. open in new tab
if (samePageLinkNavigation(event)) {
return;
}

// Ignore click meant for native link handling, e.g. open in new tab
if (samePageLinkNavigation(event)) {
const activeElement = isLink(event);
if (activeElement === null) {
return;
}

Expand Down
11 changes: 0 additions & 11 deletions examples/material-ui-nextjs-pages-router-ts/src/Link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,6 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkProps>(function Link(props,
[activeClassName]: router.pathname === pathname && activeClassName,
});

const isExternal =
typeof href === 'string' && (href.indexOf('http') === 0 || href.indexOf('mailto:') === 0);

if (isExternal) {
if (noLinkStyle) {
return <Anchor className={className} href={href} ref={ref} {...other} />;
}

return <MuiLink className={className} href={href} ref={ref} {...other} />;
}

const linkAs = linkAsProp || as;
const nextjsProps = {
to: href,
Expand Down
11 changes: 0 additions & 11 deletions examples/material-ui-nextjs-pages-router/src/Link.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,6 @@ const Link = React.forwardRef(function Link(props, ref) {
[activeClassName]: router.pathname === pathname && activeClassName,
});

const isExternal =
typeof href === 'string' && (href.indexOf('http') === 0 || href.indexOf('mailto:') === 0);

if (isExternal) {
if (noLinkStyle) {
return <Anchor className={className} href={href} ref={ref} {...other} />;
}

return <MuiLink className={className} href={href} ref={ref} {...other} />;
}

const linkAs = linkAsProp || as;
const nextjsProps = {
to: href,
Expand Down
Loading