GlLink: Set external link label only with the icon
What does this MR do?
Since !4528 (merged), link.vue binds :data-alt="externalLinkLabel" on all three template branches. It does not check any condition. So every GlLink gets data-alt="(external link)". This includes internal links, external links without the icon, and links styled as buttons.
Only one CSS rule reads the attribute:
.gl-link-external::after { content: " ↗" / attr(data-alt); }That rule applies only when the gl-link-external class is present. So the attribute is dead on every other link. This has two effects:
- The attribute is wrong on internal links. It says "(external link)" on a link that is not external.
- The attribute appears in
element.dataseton every link. GitLab spreads{ ...el.dataset }into component props andprovidein about 20 places.
This MR makes externalLinkLabel return undefined unless shouldShowExternalIcon is true. That is the same condition that adds the gl-link-external class. So the attribute now lands where the CSS reads it, and nowhere else.
Why this matters now
The unconditional attribute broke the @gitlab/ui bump in gitlab-org/gitlab!253439 (closed). 14 Jest suites failed, with 17 failed tests. None of the affected links had the gl-link-external class, so every failure came from the dead attribute.
I patched the installed package in gitlab-org/gitlab with this change and re-ran those 14 suites. All 128 tests and 18 snapshots pass, with no changes to that repo. So this fix unblocks the bump and needs no snapshot updates there.
How to validate
- Run the Vue 2 tests:
cd packages/gitlab-ui && NODE_ENV=test yarn jest src/components/base/link/link.spec.js - Run the Vue 3 tests:
cd packages/gitlab-ui && NODE_ENV=test VUE_VERSION=3 yarn jest src/components/base/link/link.spec.js - Check that all 51 tests pass in both runs.
- Revert the change to
externalLinkLabeland run the tests again. Check that 5 assertions fail.
Screenshots or screen recordings
No visual change. The rendered icon and its announced label are the same.
Integrations
- GitLab: mr_url
- CustomersDot: mr_url
- Duo UI: mr_url
- Status Page: mr_url
- Docs: mr_url
- Switchboard: mr_url
Does this MR meet the acceptance criteria?
This checklist encourages the authors, reviewers, and maintainers of merge requests (MRs) to confirm changes were analyzed for conformity with the project's guidelines, security and accessibility.
Toggle the acceptance checklist
Conformity
- The “What does this MR do?” section in the MR description is filled out, explaining the reasons for and scope of the proposed changes, per “Say why not just what”.
- For example, if the MR is focused on usage guidelines, addressing accessibility challenges could be added in a separate MR.
- Relevant label(s) are applied to the MR.
- The MR is added to a milestone.
- Added the
~"component:*"label(s) if applicable. - A changeset is added when this MR will do a patch, minor, or major update. More information can be found in
doc/changesets.md.
Components
- GitLab UI's contributing guidelines.
- If the MR changes a component's API, integration MR(s) have been opened (see integrations above).
Documentation
- If creating a new component page from scratch, it follows the page template structure.
- Content follows the GitLab Documentation Style Guide when appropriate.
- Related pages are cross-linked, where helpful. Component pages have related components and patterns defined in their Markdown front matter.
- If embedding a Figma file, it follows the Figma embed guide.
- Review requested from any GitLab designer or directly from a maintainer or trainee maintainer.
- Maintainer review follows the Pajamas UX maintainer review checklist.
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- Label as security and @ mention
@gitlab-com/gl-security/appsec - Security reports checked/validated by a reviewer from the AppSec team
Accessibility
If this MR adds or modifies a component, take a few moments to review the following:
- All actions and functionality can be done with a keyboard.
- Links, buttons, and controls have a visible focus state.
- All content is presented in text or with a text equivalent. For example, alt text for SVG, or
aria-labelfor icons that have meaning or perform actions. - Changes in a component’s state are announced by a screen reader. For example, changing
aria-expanded="false"toaria-expanded="true"when an accordion is expanded. - Color combinations have sufficient contrast.