Skip to content

Consistently use (avoid) browser prefixes for icon mask styling#3860

Merged
thisisdano merged 2 commits intouswds:developfrom
aduth:mask-icon-supports-consistency
Dec 3, 2020
Merged

Consistently use (avoid) browser prefixes for icon mask styling#3860
thisisdano merged 2 commits intouswds:developfrom
aduth:mask-icon-supports-consistency

Conversation

@aduth
Copy link
Contributor

@aduth aduth commented Dec 1, 2020

Description

The add-color-icon icon mixin uses an @supports test of (mask: url("")) or (-webkit-mask: url("")) in checking whether to add mask styling, but then only adds the styling using the unprefixed style mask:. The changes here seek to consistently use (avoid) the prefix.

Additional information

In environments where autoprefixing is not configured, this can cause strange behaviors in Chrome (v87) where -webkit-mask is supported, but the unprefixed mask is not, and yet the styles will still be applied.

Because the documentation claims that autoprefixing is a prerequisite in projects, the suggestion here is to remove the prefixed form in the @supports check. This way, the prefixing will be added by autoprefixer, but without autoprefixer, at least the styles would not be applied erroneously.

You can confirm using a tool like Autoprefixer CSS online that the prefixed form is added to a @supports directive:

.example {
  @supports (mask: url("")) {
    background: none;
    background-color: color($color);
    mask: $image-props;
    @if $color-hover {
      &:hover {
        background-color: color($color-hover);
      }
    }
  }
}

Without these changes, an autoprefixer would unnecessarily duplicate the vendor prefix:

@supports ((-webkit-mask: url("")) or (mask: url(""))) or (-webkit-mask: url("")) {

@thisisdano
Copy link
Contributor

Oh nice — I guess I didn't realize that Autoprefixer would update the @supports directive as well! This is a great fix and an excellent way to prevent this common error.

@thisisdano thisisdano merged commit 4855d3b into uswds:develop Dec 3, 2020
@aduth aduth deleted the mask-icon-supports-consistency branch December 3, 2020 20:28
@thisisdano thisisdano mentioned this pull request Dec 17, 2020
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.

2 participants