Browse Source

add id prop to NextLink

Yuki Takei 3 years ago
parent
commit
156824191f
1 changed files with 5 additions and 4 deletions
  1. 5 4
      apps/app/src/components/ReactMarkdownComponents/NextLink.tsx

+ 5 - 4
apps/app/src/components/ReactMarkdownComponents/NextLink.tsx

@@ -28,13 +28,14 @@ const isAttached = (href: string): boolean => {
 
 type Props = Omit<LinkProps, 'href'> & {
   children: React.ReactNode,
+  id?: string,
   href?: string,
   className?: string,
 };
 
 export const NextLink = (props: Props): JSX.Element => {
   const {
-    href, children, className, ...rest
+    id, href, children, className, ...rest
   } = props;
 
   const { data: siteUrl } = useSiteUrl();
@@ -51,13 +52,13 @@ export const NextLink = (props: Props): JSX.Element => {
   // when href is an anchor link
   if (isAnchorLink(href)) {
     return (
-      <a href={href} className={className} {...dataAttributes}>{children}</a>
+      <a id={id} href={href} className={className} {...dataAttributes}>{children}</a>
     );
   }
 
   if (isExternalLink(href, siteUrl)) {
     return (
-      <a href={href} className={className} target="_blank" rel="noopener noreferrer" {...dataAttributes}>
+      <a id={id} href={href} className={className} target="_blank" rel="noopener noreferrer" {...dataAttributes}>
         {children}&nbsp;<i className='icon-share-alt small'></i>
       </a>
     );
@@ -68,7 +69,7 @@ export const NextLink = (props: Props): JSX.Element => {
     const dlhref = href.replace('/attachment/', '/download/');
     return (
       <span>
-        <a href={href} className={className} target="_blank" rel="noopener noreferrer" {...dataAttributes}>
+        <a id={id} href={href} className={className} target="_blank" rel="noopener noreferrer" {...dataAttributes}>
           {children}
         </a>&nbsp;
         <a href={dlhref} className="attachment-download"><i className='icon-cloud-download'></i></a>