From 3cfc342cc1fb4ff9cf7dccee146a8345ba03bf89 Mon Sep 17 00:00:00 2001 From: Michail Yasonik Date: Thu, 22 Oct 2020 14:48:02 -0400 Subject: [PATCH 1/6] adds opens in new target text for links for screen readers --- .../link/__snapshots__/link.test.tsx.snap | 8 +++++++- src/components/link/link.tsx | 13 +++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/components/link/__snapshots__/link.test.tsx.snap b/src/components/link/__snapshots__/link.test.tsx.snap index 16d5594bdf3..41f62d0fe34 100644 --- a/src/components/link/__snapshots__/link.test.tsx.snap +++ b/src/components/link/__snapshots__/link.test.tsx.snap @@ -129,7 +129,13 @@ exports[`EuiLink supports target 1`] = ` href="#" rel="noreferrer" target="_parent" -/> +> + + (opens in a new tab or window) + + `; exports[`EuiLink text is rendered 1`] = ` diff --git a/src/components/link/link.tsx b/src/components/link/link.tsx index 89ee12df59b..bf11358dfd0 100644 --- a/src/components/link/link.tsx +++ b/src/components/link/link.tsx @@ -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 = @@ -115,6 +116,17 @@ const EuiLink = forwardRef( ) : undefined; + const newTargetScreenreaderText = target ? ( + + + + + + ) : undefined; + if (href === undefined) { const buttonProps = { className: classNames( @@ -153,6 +165,7 @@ const EuiLink = forwardRef( {...(anchorProps as EuiLinkAnchorProps)}> {children} {externalLinkIcon} + {newTargetScreenreaderText} ); } From 212bbfa3ddb66684a6c2d7a469de0a41e0bd58de Mon Sep 17 00:00:00 2001 From: Michail Yasonik Date: Wed, 28 Oct 2020 12:50:04 -0400 Subject: [PATCH 2/6] PR feedback --- src-docs/src/views/link/link.js | 10 +++-- .../link/__snapshots__/link.test.tsx.snap | 24 +++++++++- src/components/link/link.test.tsx | 9 +++- src/components/link/link.tsx | 45 +++++++++---------- 4 files changed, 58 insertions(+), 30 deletions(-) diff --git a/src-docs/src/views/link/link.js b/src-docs/src/views/link/link.js index 3ba7288cfc3..9c56a8a10d8 100644 --- a/src-docs/src/views/link/link.js +++ b/src-docs/src/views/link/link.js @@ -9,14 +9,15 @@ export default () => ( Elastic website {' '} - in a new tab. + in a new tab. Setting target=“_blank” also + defaults to external={true}.

This{' '} - + link {' '} - has the external prop set to true. + has the external prop set to false.

This link is actually a{' '} @@ -34,7 +35,8 @@ export default () => ( }}> link {' '} - with both an href and an onClick handler. + with both an href and an onClick{' '} + handler.

Links can be colored as well.

    diff --git a/src/components/link/__snapshots__/link.test.tsx.snap b/src/components/link/__snapshots__/link.test.tsx.snap index 41f62d0fe34..e486d8e306c 100644 --- a/src/components/link/__snapshots__/link.test.tsx.snap +++ b/src/components/link/__snapshots__/link.test.tsx.snap @@ -7,6 +7,21 @@ exports[`EuiLink accent is rendered 1`] = ` /> `; +exports[`EuiLink allows for target and external to be controlled independently 1`] = ` + + + (opens in a new tab or window) + + +`; + exports[`EuiLink button respects the type property 1`] = `