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

Added external prop to EuiLink #2442

Merged
merged 11 commits into from
Oct 17, 2019
Merged

Conversation

andreadelrio
Copy link
Contributor

@andreadelrio andreadelrio commented Oct 16, 2019

Summary

This PR adds external as an opt-in prop to EuiLink. Setting the prop to true adds the popout icon next to the link. Covers #2079

image

Checklist

- [ ] Checked in dark mode
- [ ] Checked in mobile

  • Checked in IE11 and Firefox
  • Props have proper autodocs
  • Added documentation examples
  • Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

Copy link
Contributor

@cchaos cchaos left a 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-docs/src/views/link/link.js Outdated Show resolved Hide resolved
src/components/link/_link.scss Outdated Show resolved Hide resolved
@@ -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}
Copy link
Contributor

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:

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">
&hellip;
</EuiBadge>
)}
</EuiI18n>
);

Copy link
Contributor

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the small size works a lot better
image

Copy link
Contributor Author

@andreadelrio andreadelrio Oct 16, 2019

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:

Added the aria-label, I tried adding a title but was getting this error:

image

Copy link
Contributor

@cchaos cchaos left a 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.

@@ -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">
Copy link
Contributor

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

Suggested change
<EuiI18n token="euiLink.external.ariaLabel" default="External Link">
<EuiI18n token="euiLink.external.ariaLabel" default="External link">

@@ -111,6 +132,7 @@ const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>(
ref={ref as React.Ref<HTMLAnchorElement>}
{...anchorProps as EuiLinkAnchorProps}>
{children}
{external ? externalLinkIcon : undefined}
Copy link
Contributor

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

Suggested change
{external ? externalLinkIcon : undefined}
{externalLinkIcon}

Copy link
Contributor Author

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.

Copy link
Contributor

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))
Copy link
Contributor

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

@@ -57,13 +61,32 @@ export type EuiLinkProps = ExclusiveUnion<
EuiLinkAnchorProps
>;

const EuiLink = forwardRef<HTMLAnchorElement | HTMLButtonElement, EuiLinkProps>(
const externalLinkIcon = external ? ( // eslint-disable-line no-restricted-globals
Copy link
Contributor

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().

Copy link
Contributor

@cchaos cchaos left a 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))
Copy link
Contributor

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

@andreadelrio andreadelrio merged commit 5437331 into elastic:master Oct 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants