Problem/Motivation

Based on: https://developer.mozilla.org/en-US/docs/Web/CSS/color_value/rgb
It's recommended to use rgb(), not rgba(), also for colors with transparency.

Steps to reproduce

Configure formatter to display value as RGB. For fields with transparency enabled, it uses rgba().

Proposed resolution

Replace colors in rgba (e.g. rgba(0, 0, 0, 0.5)) with colors in rgb (e.g. rgb(0, 0, 0 / 0.5)).

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

gugalamaciek created an issue. See original summary.

gugalamaciek’s picture

StatusFileSize
new641 bytes
gugalamaciek’s picture

gugalamaciek’s picture

Assigned: gugalamaciek » Unassigned
Status: Active » Needs review
gugalamaciek’s picture

Title: Use rgb() instead of rgba() (which is alias of rgb()) » Use rgb() instead of rgba() for RGB color
gugalamaciek’s picture

StatusFileSize
new834 bytes

Replace comas with spaces, so now this is returned:
rgb(0 0 0)
rgb(0 0 0 / 0.5)

anirudhsingh19’s picture

reviewing this!

anirudhsingh19’s picture

Status: Needs review » Needs work
StatusFileSize
new20.78 KB
new19.57 KB

The patch works fine. Please provide a MR as patches are not recommended anymore.

macsim made their first commit to this issue’s fork.

macsim’s picture

Status: Needs work » Needs review

Applied the patch from #6 and updated the PHPUnit functional tests accordingly.

The ColorRGB::toString() method now uses the modern CSS color syntax:

  • rgb(r g b / a) when opacity is enabled and the value is not 1.0
  • rgb(r g b) when opacity is disabled or equals 1.0 (fully opaque)

All assertions in ColorFieldFormatterTest and ColorFieldFormatterTokenTest have been updated to reflect the new output format.

eslint warnings are not related to those changes

mandclu’s picture

Version: 3.0.x-dev » 3.1.x-dev

  • mandclu committed d41cc455 on 3.1.x authored by macsim
    task: #3542956 Use rgb() instead of rgba() for RGB color
    
    By:...
mandclu’s picture

Status: Needs review » Fixed

Thanks for everyone's work here. Merged into a new 3.1.x branch.

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.