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

Adds 'opens in new target' text for links for screen readers #4172

Merged
merged 7 commits into from
Oct 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion src/components/link/__snapshots__/link.test.tsx.snap
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,13 @@ exports[`EuiLink supports target 1`] = `
href="#"
rel="noreferrer"
target="_parent"
/>
>
<span
class="euiScreenReaderOnly"
>
(opens in a new tab or window)
</span>
</a>
`;

exports[`EuiLink text is rendered 1`] = `
Expand Down
13 changes: 13 additions & 0 deletions src/components/link/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { EuiIcon } from '../icon';
import { EuiI18n } from '../i18n';
import { CommonProps, ExclusiveUnion, keysOf } from '../common';
import { getSecureRelForTarget } from '../../services';
import { EuiScreenReaderOnly } from '../accessibility';

export type EuiLinkType = 'button' | 'reset' | 'submit';
export type EuiLinkColor =
Expand Down Expand Up @@ -115,6 +116,17 @@ const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>(
</EuiI18n>
) : undefined;

const newTargetScreenreaderText = target ? (
myasonik marked this conversation as resolved.
Show resolved Hide resolved
<EuiScreenReaderOnly>
<span>
<EuiI18n
token="euiLink.newTarget.screenReaderOnlyText"
default="(opens in a new tab or window)"
/>
</span>
</EuiScreenReaderOnly>
) : undefined;

if (href === undefined) {
const buttonProps = {
className: classNames(
Expand Down Expand Up @@ -153,6 +165,7 @@ const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>(
{...(anchorProps as EuiLinkAnchorProps)}>
{children}
{externalLinkIcon}
{newTargetScreenreaderText}
</a>
);
}
Expand Down