Skip to content

Commit

Permalink
Add tooltip around links
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Oct 20, 2020
1 parent a73e977 commit 68143c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,30 @@
*/

import React, { memo } from 'react';
import { EuiLink, EuiLinkAnchorProps } from '@elastic/eui';
import { EuiLink, EuiLinkAnchorProps, EuiToolTip } from '@elastic/eui';

type MarkdownLinkProps = { disableLinks?: boolean } & EuiLinkAnchorProps;

/** prevents search engine manipulation by noting the linked document is not trusted or endorsed by us */
const REL_NOFOLLOW = 'nofollow';

const MarkdownLinkComponent: React.FC<MarkdownLinkProps> = ({
disableLinks,
href,
target,
children,
...props
}) => (
<>
{disableLinks ? (
<span>{children}</span>
) : (
<EuiLink
{...props}
target="_blank"
data-test-subj="markdown-link"
href={disableLinks ? undefined : href}
rel="nofollow"
>
{children}
</EuiLink>
)}
</>
<EuiToolTip content={href}>
<EuiLink
href={disableLinks ? undefined : href}
data-test-subj="markdown-link"
rel={`${REL_NOFOLLOW}`}
target="_blank"
>
{children}
</EuiLink>
</EuiToolTip>
);

export const MarkdownLink = memo(MarkdownLinkComponent);
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ describe('Markdown', () => {
<MarkdownRenderer disableLinks={true}>{markdownWithLink}</MarkdownRenderer>
);

expect(wrapper.find('[data-test-subj="markdown-link"]').exists()).toBeFalsy();
expect(
wrapper.find('[data-test-subj="markdown-link"]').first().getDOMNode()
).not.toHaveProperty('href');
});

test('it opens links in a new tab via target="_blank"', () => {
Expand Down

0 comments on commit 68143c4

Please sign in to comment.