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

refactor: only show external icon for link + button when external prop is used #689

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

melaniebmn
Copy link
Collaborator

Summary | Résumé

While working on the new page templates for our docs site, I saw an opportunity to improve the behavior of the link and button components, specifically regarding the display of the external icon. Previously, the external icon was shown whenever the target="_blank" attribute was used, but it should only appear for links pointing to external, non-canada.ca pages. I updated the code to display the external icon only when the external prop is present on either component. This change now allows users to set target="_blank" on internal links without triggering the external icon, ensuring more accurate and consistent behavior.

ethanWallace
ethanWallace previously approved these changes Nov 18, 2024
Copy link
Collaborator

@ethanWallace ethanWallace left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@daine daine left a comment

Choose a reason for hiding this comment

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

This is good, just have a few comments! We also may need to loop design in so they can add these properties in the figma components.

});
expect(root).toEqualHtml(`
<gcds-link href="https://google.com" target="_blank" lang="fr">
<gcds-link href="https://google.com" external lang="fr">
Copy link
Collaborator

@daine daine Nov 18, 2024

Choose a reason for hiding this comment

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

We already have it added to the index.html below, but can we also add it to the test? Let's add one test for:

// This link opens in a new tab, but is not external.
<gcds-link target="_blank"> 

Comment on lines 117 to 120
/**
* Whether the link is external or not
*/
@Prop() external?: boolean = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because this is a prop change, I think it would be a good idea to be specific here since it only applies if the button is type="link"

Suggested change
/**
* Whether the link is external or not
*/
@Prop() external?: boolean = false;
/**
* Set to true if the button is meant to link to an external page. Requires property `type` to be set to `"link"` for this to work.
*/
@Prop() externalLink?: boolean = false;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good idea!

});
expect(root).toEqualHtml(`
<gcds-button type="link" button-style="text-only" href="https://google.com" target="_blank">
<gcds-button type="link" href="https://google.com" external>
Copy link
Collaborator

@daine daine Nov 18, 2024

Choose a reason for hiding this comment

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

Can we also add a test for "target=_blank", when we are not displaying the external icon? For internal pages that we want to open on another page? Is that possible? I'm thinking it's the same behaviour for the link.

Copy link
Collaborator

@daine daine left a comment

Choose a reason for hiding this comment

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

Just one last item that we discussed during sync earlier

* Set to true if the button links to an external page.
* Requires the "type" to be set to "link" to work.
*/
@Prop() external?: boolean = false;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it possible to separate the new prop from this PR so we don't introduce a change to this component for now? We can add a prop in a separate PR and go through a component update process.

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