-
Notifications
You must be signed in to change notification settings - Fork 843
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
Added external prop to EuiLink #2442
Conversation
[external-link] interface and props table fix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking this one on! Just a couple comments.
src/components/link/link.tsx
Outdated
@@ -111,6 +118,7 @@ const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>( | |||
ref={ref as React.Ref<HTMLAnchorElement>} | |||
{...anchorProps as EuiLinkAnchorProps}> | |||
{children} | |||
{external ? <EuiIcon type="popout" /> : undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably pass an aria-label
and title
attribute to the icon explaining that the icon is indicating an external link. But they'll also need to be translated, so you'll need to use the Eui18n component similar to this usage:
eui/src/components/breadcrumbs/breadcrumbs.tsx
Lines 96 to 111 in fab513d
const ellipsisButton = ( | |
<EuiI18n | |
token="euiBreadcrumbs.collapsedBadge.ariaLabel" | |
default="Show all breadcrumbs"> | |
{(ariaLabel: string) => ( | |
<EuiBadge | |
aria-label={ariaLabel} | |
onClick={() => setIsPopoverOpen(!isPopoverOpen)} | |
onClickAriaLabel={ariaLabel} | |
title="View hidden breadcrumbs" | |
className="euiBreadcrumb euiBreadcrumb__collapsedBadge"> | |
… | |
</EuiBadge> | |
)} | |
</EuiI18n> | |
); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, what do you think about making this size="s"
so that it becomes more subtle?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probably pass an
aria-label
andtitle
attribute to the icon explaining that the icon is indicating an external link. But they'll also need to be translated, so you'll need to use the Eui18n component similar to this usage:
Added the aria-label
, I tried adding a title
but was getting this error:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh yeah, I forgot that SVG doesn't accept title
attributes. We can just leave it as the aria-label
for now.
One other thing is you should create another test case for this new property in the test file and update the snapshots. You should be able to just copy and paste and follow the pattern of the other props. I added that line item back to the checklist in the summary. Let me know if you need any help doing so.
src/components/link/link.tsx
Outdated
@@ -57,13 +61,30 @@ export type EuiLinkProps = ExclusiveUnion< | |||
EuiLinkAnchorProps | |||
>; | |||
|
|||
const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>( | |||
const externalLinkIcon = ( | |||
<EuiI18n token="euiLink.external.ariaLabel" default="External Link"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remember to use sentence case
<EuiI18n token="euiLink.external.ariaLabel" default="External Link"> | |
<EuiI18n token="euiLink.external.ariaLabel" default="External link"> |
src/components/link/link.tsx
Outdated
@@ -111,6 +132,7 @@ const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>( | |||
ref={ref as React.Ref<HTMLAnchorElement>} | |||
{...anchorProps as EuiLinkAnchorProps}> | |||
{children} | |||
{external ? externalLinkIcon : undefined} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Optional cleanup idea
Since the display of the external icon is tied to a property, you can also save some JS computing by setting the value of externalLinkIcon
depending on the external
property like so:
const externalLinkIcon = external ? (
<EuiI18n token="euiLink.external.ariaLabel" default="External link">
{...}
</EuiI18n>
) : undefined;
and so then this line is simplified to be just
{external ? externalLinkIcon : undefined} | |
{externalLinkIcon} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@cchaos I did the optional cleanup you suggested. I was getting this error 64:26 error Unexpected use of 'external' no-restricted-globals
so I did // eslint-disable-line no-restricted-globals
Let me know if that's the way to go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a comment below, but essentially, this code needs to be within the EuiLink component, not outside of it.
CHANGELOG.md
Outdated
@@ -16,6 +16,7 @@ | |||
- Added `keyboardShorcut` glyph to 'EuiIcon ([#2413](https://github.com/elastic/eui/pull/2413)) | |||
- Improved a11y in `EuiNavDrawer` ([#2417](https://github.com/elastic/eui/pull/2417)) | |||
- Improved a11y in `EuiSuperDatePicker` ([#2426](https://github.com/elastic/eui/pull/2426)) | |||
- Added `external` prop to `EuiLink` ([#2442](https://github.com/elastic/eui/pull/2410)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This CL line now needs to be moved up below master
src/components/link/link.tsx
Outdated
@@ -57,13 +61,32 @@ export type EuiLinkProps = ExclusiveUnion< | |||
EuiLinkAnchorProps | |||
>; | |||
|
|||
const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>( | |||
const externalLinkIcon = external ? ( // eslint-disable-line no-restricted-globals |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I didn't catch this before, but the reason you were getting the eslint error is because external
only exists within EuiLink. You'll need to move this to within the component code before the return()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but there's a small error in the CL. Once that's fixed, it's good to merge!
CHANGELOG.md
Outdated
@@ -1,6 +1,7 @@ | |||
## [`master`](https://github.com/elastic/eui/tree/master) | |||
|
|||
- Added ability for `EuiColorStops` to accept user-defined range bounds ([#2396](https://github.com/elastic/eui/pull/2396)) | |||
- Added `external` prop to `EuiLink` ([#2442](https://github.com/elastic/eui/pull/2410)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link is pointing to the wrong PR
Summary
This PR adds
external
as an opt-in prop toEuiLink
. Setting the prop to true adds the popout icon next to the link. Covers #2079Checklist
- [ ] Checked in dark mode- [ ] Checked in mobile- [ ] Checked for breaking changes and labeled appropriately- [ ] Checked for accessibility including keyboard-only and screenreader modes