-
Notifications
You must be signed in to change notification settings - Fork 16
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
base: main
Are you sure you want to change the base?
Conversation
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!
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 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"> |
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.
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">
/** | ||
* Whether the link is external or not | ||
*/ | ||
@Prop() external?: boolean = false; |
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.
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"
/** | |
* 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; |
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.
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> |
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.
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.
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.
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; |
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.
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.
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 theexternal
prop is present on either component. This change now allows users to settarget="_blank"
on internal links without triggering the external icon, ensuring more accurate and consistent behavior.