Fixed inline links opening in new tab for external links; fixed scrolling to container if hash is provided

This commit is contained in:
Piotr Janosz
2019-08-20 16:35:18 +02:00
committed by fabioberger
parent 487bc1a08b
commit 1005e4962a
2 changed files with 4 additions and 5 deletions

View File

@@ -1,6 +1,7 @@
import * as React from 'react';
import { Link } from 'ts/components/documentation/shared/link';
import { docs } from 'ts/style/docs';
interface IInlineLinkProps {
children: React.ReactNode;
@@ -8,8 +9,10 @@ interface IInlineLinkProps {
}
export const InlineLink: React.FC<IInlineLinkProps> = ({ children, href }) => {
const to = href.replace(/#/, ''); // Remove hash from internal links so that react-scroll can find the target
return (
<Link containerId="" to={href} textDecoration="underline">
<Link containerId="" offset={-docs.headerOffset} shouldOpenInNewTab={true} to={to} textDecoration="underline">
{children}
</Link>
);

View File

@@ -69,10 +69,6 @@ export class Link extends React.Component<LinkProps, LinkState> {
type = LinkType.ReactScroll;
}
if (type === LinkType.ReactScroll && this.props.shouldOpenInNewTab) {
throw new Error(`Cannot open LinkType.ReactScroll links in new tab. link.to: ${this.props.to}`);
}
const styleWithDefault = {
textDecoration: this.props.textDecoration,
cursor: 'pointer',