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

feat(link): warn if link opens in new tab but no tooltip or label for icon is provided #710

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

gabrielchl
Copy link
Collaborator

IMPORTANT

Currently, this project is closed to any external contributions. Any pull request made against this project from external sources will likely be closed. If you would like to make changes to this project, please fork this project.

Guide

This "Help" section can be deleted before submitting this pull request.

Update the name of this pull request to reflect the following shape:

{type}/{scope?}/{message}
  • type - A conventional commit type REQUIRED
  • scope - The kabab-case scope of the changes in this request
  • message - A short, kebab-case statement describing the changes REQUIRED

Provide a general summary of the scope of the changes in this pull request.

Description

see title

Links

https://jira-eng-gpk2.cisco.com/jira/browse/SPARK-582981

Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion:
Line 234: could you add a tooltipContent prop to silence the console warn

Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion:
could you add a test to check that it outputs the warning

Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: Overflow is broken

pr master
image image

</div>
</a>
);

return (
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for simplifying it

@@ -37,12 +37,12 @@ const Link = forwardRef((props: Props, providedRef: RefObject<HTMLAnchorElement>

Copy link
Collaborator

Choose a reason for hiding this comment

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

we should add a warn here:

if(isExternalLink && !hasExternalLinkIcon) {
      console.warn(
      'MRV2: The link opens a new tab and it has no external link icon indicating this. Please pass hasExternalLinkIcon: true to the icon'
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if it's external link and hasExternalLinkIcon is undefined, it'll automatically render the icon
whether the icon is rendered is not solely based on the hasExternalLinkIcon prop

isShowIcon = true;
} else if (hasExternalLinkIcon) {
isShowIcon = true;
if (isShowIcon && !tooltipContent && !externalLinkIconProps?.['aria-label']) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we are allowing the developer to have an icon that is not labelled visibly, only with aria-label. So that violates one of the icon rules.

Maybe it could be:

const isShowExternalIcon = hasExternalLinkIcon || (hasExternalLinkIcon === undefined && isExternalLink);

if (isShowIcon && !tooltipContent) {
    console.warn(
      'MRV2: This link is external link, so an indicator icon will be shown next to it. All meaningful icons need a tooltip, so please pass tooltipContent="Opens a new tab" to the link'
    );
}

{!tooltipContent && <a {...commonProps}>{props.children}</a>}
</>
{tooltipContent ? (
<Tooltip type={tooltipType} placement="bottom" triggerComponent={content}>
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should default our tooltipType to "description", so that the SR reads '{content of the link}, Opens a new tab, Link'. Maybe we should not even allow the user to pass a tootlipType so that this is the only allowed behaviour

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