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

fix: Additional word is being announced by screen reader for the external links #8065

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions packages/eui/changelogs/upcoming/8065.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
**Accessibility**

- Improved accessibility of `EuiExternalLinkIcon` by clarifying text for Screen Reader users.

Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,12 @@ exports[`EuiCollapsibleNavLink renders a link 1`] = `
<span
class="emotion-EuiExternalLinkIcon"
data-euiicon-type="popout"
>
External link
</span>
role="presentation"
/>
<span
class="emotion-euiScreenReaderOnly"
>
(opens in a new tab or window)
(external, opens in a new tab or window)
</span>
</a>
`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ exports[`EuiLink it is an external link 1`] = `
<span
class="emotion-EuiExternalLinkIcon"
data-euiicon-type="popout"
role="presentation"
/>
<span
class="emotion-euiScreenReaderOnly"
>
External link
(external)
</span>
</a>
`;
Expand Down Expand Up @@ -134,13 +138,12 @@ exports[`EuiLink supports target 1`] = `
<span
class="emotion-EuiExternalLinkIcon"
data-euiicon-type="popout"
>
External link
</span>
role="presentation"
/>
<span
class="emotion-euiScreenReaderOnly"
>
(opens in a new tab or window)
(external, opens in a new tab or window)
</span>
</a>
`;
Expand Down
23 changes: 9 additions & 14 deletions packages/eui/src/components/link/external_link_icon.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ describe('EuiExternalLinkIcon', () => {
<span
class="emotion-EuiExternalLinkIcon"
data-euiicon-type="popout"
role="presentation"
/>
<span
class="emotion-euiScreenReaderOnly"
>
External link
(external)
</span>
</div>
`);
Expand All @@ -38,13 +42,12 @@ describe('EuiExternalLinkIcon', () => {
<span
class="emotion-EuiExternalLinkIcon"
data-euiicon-type="popout"
>
External link
</span>
role="presentation"
/>
<span
class="emotion-euiScreenReaderOnly"
>
(opens in a new tab or window)
(external, opens in a new tab or window)
</span>
</div>
`);
Expand All @@ -54,15 +57,7 @@ describe('EuiExternalLinkIcon', () => {
const { container } = render(
<EuiExternalLinkIcon target="_blank" external={false} />
);
expect(container).toMatchInlineSnapshot(`
<div>
<span
class="emotion-euiScreenReaderOnly"
>
(opens in a new tab or window)
</span>
</div>
`);
expect(container).toMatchInlineSnapshot(`<div />`);
});
});

Expand Down
54 changes: 31 additions & 23 deletions packages/eui/src/components/link/external_link_icon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import React, { FunctionComponent, AnchorHTMLAttributes } from 'react';
import { useEuiMemoizedStyles, UseEuiTheme } from '../../services';
import { logicalStyle } from '../../global_styling';
import { EuiIcon, EuiIconProps } from '../icon';
import { EuiI18n, useEuiI18n } from '../i18n';
import { EuiI18n } from '../i18n';
import { EuiScreenReaderOnly } from '../accessibility';

/**
Expand Down Expand Up @@ -39,31 +39,39 @@ export const EuiExternalLinkIcon: FunctionComponent<
const showExternalLinkIcon =
(target === '_blank' && external !== false) || external === true;

const iconAriaLabel = useEuiI18n(
'euiExternalLinkIcon.ariaLabel',
'External link'
);

return (
<>
{showExternalLinkIcon && (
<EuiIcon
css={iconCssStyle}
aria-label={iconAriaLabel}
size="s"
type="popout"
{...rest}
/>
)}
{target === '_blank' && (
<EuiScreenReaderOnly>
<span>
<EuiI18n
token="euiExternalLinkIcon.newTarget.screenReaderOnlyText"
default="(opens in a new tab or window)"
/>
</span>
</EuiScreenReaderOnly>
<>
<EuiIcon
css={iconCssStyle}
size="s"
type="popout"
role="presentation"
{...rest}
/>
{target === '_blank' ? (
<EuiScreenReaderOnly>
<span>
<EuiI18n
token="euiExternalLinkIcon.newTarget.screenReaderOnlyText"
default="(external, opens in a new tab or window)"
/>
</span>
</EuiScreenReaderOnly>
) : (
<>
<EuiScreenReaderOnly>
<span>
<EuiI18n
token="euiExternalLinkIcon.externalTarget.screenReaderOnlyText"
default="(external)"
/>
</span>
</EuiScreenReaderOnly>
</>
)}
</>
)}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,16 @@ describe('EuiListGroupItem', () => {
const { getByText } = render(
<EuiListGroupItem label="Label" href="#" external />
);
expect(getByText('External link')).toBeInTheDocument();
expect(getByText('(external)')).toBeInTheDocument();
});

test('target `_blank` renders external icon', () => {
const { getByText } = render(
<EuiListGroupItem label="Label" href="#" target="_blank" />
);
expect(getByText('External link')).toBeInTheDocument();
expect(
getByText('(external, opens in a new tab or window)')
).toBeInTheDocument();
});
});

Expand Down
Loading