diff --git a/docs/pages/blog.tsx b/docs/pages/blog.tsx index 65f3bd3718eb3c..f34f69537a9435 100644 --- a/docs/pages/blog.tsx +++ b/docs/pages/blog.tsx @@ -81,7 +81,7 @@ function PostPreview(props: BlogPost) { > { - // 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; } diff --git a/docs/src/modules/components/AppTableOfContents.js b/docs/src/modules/components/AppTableOfContents.js index 529b07b1ddbcc3..1799a536444806 100644 --- a/docs/src/modules/components/AppTableOfContents.js +++ b/docs/src/modules/components/AppTableOfContents.js @@ -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; } diff --git a/docs/src/modules/components/Link.tsx b/docs/src/modules/components/Link.tsx index e2784218dbe619..57c4b21a67e4d9 100644 --- a/docs/src/modules/components/Link.tsx +++ b/docs/src/modules/components/Link.tsx @@ -96,18 +96,8 @@ const Link = React.forwardRef(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 ; - } - - return ; - } - let linkAs = linkAsProp || as || (href as string); if ( userLanguage !== 'en' && diff --git a/docs/src/modules/components/MarkdownLinks.js b/docs/src/modules/components/MarkdownLinks.js index 495c29bf5ceca8..8f71b7320a9650 100644 --- a/docs/src/modules/components/MarkdownLinks.js +++ b/docs/src/modules/components/MarkdownLinks.js @@ -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; } @@ -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; } diff --git a/examples/material-ui-nextjs-pages-router-ts/src/Link.tsx b/examples/material-ui-nextjs-pages-router-ts/src/Link.tsx index b1bae7492a447e..06f97155f31239 100644 --- a/examples/material-ui-nextjs-pages-router-ts/src/Link.tsx +++ b/examples/material-ui-nextjs-pages-router-ts/src/Link.tsx @@ -82,17 +82,6 @@ const Link = React.forwardRef(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 ; - } - - return ; - } - const linkAs = linkAsProp || as; const nextjsProps = { to: href, diff --git a/examples/material-ui-nextjs-pages-router/src/Link.js b/examples/material-ui-nextjs-pages-router/src/Link.js index bea600669a4fa1..cff6874164af79 100644 --- a/examples/material-ui-nextjs-pages-router/src/Link.js +++ b/examples/material-ui-nextjs-pages-router/src/Link.js @@ -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 ; - } - - return ; - } - const linkAs = linkAsProp || as; const nextjsProps = { to: href,