Skip to content

USWDS - Links: Fix external link icon issues #5046

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

Merged
merged 6 commits into from
Feb 28, 2023

Conversation

mejiaj
Copy link
Contributor

@mejiaj mejiaj commented Nov 18, 2022

Description

uswds-1918-2022-11-21.at.14.50.09.webm

Fixed icon wrapping and safari display issues in external links. Improved wrapping so icon doesn't break on its own and causes display issues with punctuation. There's also an improved way for getting around Safari display issues (transparent gradient). Closes #4977.

add-color-icon mixin now allows more control over positioning. The $icon-object that gets passed to add-color-icon mixin now takes attributes for x and y positioning. These are used for both background and mask positioning.

Defaults

  • position-y: center
  • position-x: center

Additional information

This has been a tricky issue to debug and fix. The original attempt (#3395) later caused a background bleed issue in Safari (#4439). Now both issues should be resolved.

Link and icon wrapping bug

Both the link and pseudoelement have been made inline elements. The icon sizing is controlled via padding-left and background/mask size.

Safari display bug

Icon with transparent gradient on mask
image

Background bleeding has been resolved by adding a transparent linear gradient to masks.

Related issues

Browsers tested

  • Safari 16
  • Edge 107.0.1418.42 (chromium)
  • Firefox 108

How to test

I've also created a test branch in Site you can use for additional testing.

  • There shouldn't be any visual regressions in external links
  • There shouldn't be any visual regressions with external links in Safari
  • There shouldn't be any visual regressions in external link background image fallback
  • Punctuation shouldn't break into it's own line following external link
  • External link icon shouldn't break into it's own line

Before you hit Submit, make sure you’ve done whichever of these applies to you:

  • Follow the 18F Front End Coding Style Guide and Accessibility Guide.
  • Run npm test and make sure the tests for the files you have changed have passed.
  • Run your code through HTML_CodeSniffer and make sure it’s error free.
  • Title your pull request using this format: [Website] - [UI component]: Brief statement describing what this pull request solves.

James Mejia added 6 commits November 18, 2022 12:24
- Add SassDoc comments to mixin
- Allow user to set positioning in icon object
- External links are now inline to prevent wrapping issues #3395 #4977
- $icon-object now takes x and y position settings for add-color-icon mixin
- add-color-icon sets transparent gradient for Safari display issue #4434
- Remove non-breaking space in favor of margin-left
- Use padding-left for creating icon width
- Improve alignment via vertical align middle
@@ -77,7 +77,9 @@
// ($base, $variant, $variant-alt, $bg)
// the mixin will pick IE11-compatible svgs named
// [base]-[variant].svg based on the specified background-color

//
// @param {Map} - $icon-object - name, svg-height, svg-width, height, container-height, container-width, color, color-variant, color-hover, rotate, path, background-p
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added Sassdoc style comments to document the types of things $icon-object accepts in this mixin.

Comment on lines 129 to 138
$position-y: if(
map.has-key($icon-object, "position-y"),
map.get($icon-object, "position-y"),
bottom
);
$position-x: if(
map.has-key($icon-object, "position-x"),
map.get($icon-object, "position-x"),
center
);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New settings to allow user more control over icon positioning for background/mask image.

Defaults for both are center.

mask-position: $position-x $position-y;
mask-size: $width $height;
mask-repeat: no-repeat;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Stopped using shorthands for background and mask properties to allow user more control in overrides.

@mejiaj mejiaj marked this pull request as ready for review November 21, 2022 21:17
@mejiaj mejiaj requested a review from amyleadem November 21, 2022 21:17
@jhancock532
Copy link

jhancock532 commented Nov 23, 2022

I'm not certain, but I believe display: inline-block; was added due to an issue with how the external link icon renders in Firefox. After removing the display: inline-block; rule, resizing the container causes the icon render incorrectly at pixel specific widths.

external-link-icon

A potential solution is to use position: relative; for the link icon instead of position: absolute;, changing margin positioning to bottom: 2ex; or similar.

Copy link
Contributor

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

@mejiaj
Nice fix! I like the ability to customize positioning.

Everything seems to be behaving in Firefox, Chrome, and Edge. I did notice that Safari is still showing icon line breaks in the footer and identifier. However, I do not see the same issue in any of the external links in the main content of the links page in Safari.

I noticed that if I delete this extra space in the html via inspector, it resolves the issue. So I suspect this is more of an issue with uswds-site markup, but wanted to flag it for your consideration in case something else is at play.
image

Safari, 1040px
image

iOS Safari
image

  • There shouldn't be any visual regressions in external links
  • There shouldn't be any visual regressions with external links in Safari
  • There shouldn't be any visual regressions in external link background image fallback
  • Punctuation shouldn't break into it's own line following external link
  • External link icon shouldn't break into it's own line

@mejiaj
Copy link
Contributor Author

mejiaj commented Nov 30, 2022

Hey @jhancock532, thanks for taking a look at this PR. Were you experiencing the same issues in the test preview for the site?

If so, would you mind sharing what OS and browser (with version) you used?


I'll also take a look at that spacing issue you mentioned @amyleadem, thanks!

@jhancock532
Copy link

@mejiaj I was testing this on MacOS Monterey with the latest version of Firefox at that time (107), but I'm unable to replicate this issue using Firefox and the testing site. I think the code changes you've made here have resolved the problem.

@mejiaj
Copy link
Contributor Author

mejiaj commented Dec 1, 2022

Fantastic, thanks for checking @jhancock532.

@mejiaj
Copy link
Contributor Author

mejiaj commented Dec 1, 2022

@amyleadem after looking into it some more these whitespaces are specific to site. Created a separate issue for identifier links uswds/uswds-site#1928. I'll push a fix and re-request review. Good find!

image

@mejiaj mejiaj requested a review from amyleadem December 2, 2022 14:48
@mejiaj
Copy link
Contributor Author

mejiaj commented Dec 2, 2022

This PR is ready for review. The safari whitespace issue in identifier links has been fixed in uswds/uswds-site@dbb6795.

This PR must be merged before the site PR.

Copy link
Contributor

@amyleadem amyleadem left a comment

Choose a reason for hiding this comment

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

Looks good!

@mejiaj mejiaj requested a review from thisisdano December 2, 2022 17:53
@mejiaj mejiaj added this to the uswds 3.4.0 milestone Dec 21, 2022
Copy link
Contributor

@thisisdano thisisdano 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 an important fix. Nice work!

@thisisdano thisisdano merged commit fc31c6e into develop Feb 28, 2023
@thisisdano thisisdano mentioned this pull request Mar 9, 2023
@mejiaj mejiaj deleted the jm-external-link-wrapping branch July 18, 2023 16:52
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.

USWDS - Bug: External Links punctuation break
4 participants