Skip to content

Transparency checks should also cover colors other than rgba(0, 0, 0, 0), e.g. rgba(255, 255, 255, 0) #35

@romainmenke

Description

@romainmenke

Using HTMLCS.util.colourStrToRGB(bgColour).alpha seems to work as expected:

---
 .../WCAG2AAA/Sniffs/Principle1/Guideline1_4/1_4_3_Contrast.js | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_4/1_4_3_Contrast.js b/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_4/1_4_3_Contrast.js
index 9e8311b..dd11271 100644
--- a/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_4/1_4_3_Contrast.js
+++ b/Standards/WCAG2AAA/Sniffs/Principle1/Guideline1_4/1_4_3_Contrast.js
@@ -80,7 +80,7 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_4_1_4_3_Contrast = {
                         }
 
                         // Check for a solid background colour.
-                        while ((bgColour === 'transparent') || (bgColour === 'rgba(0, 0, 0, 0)')) {
+                        while ((bgColour === 'transparent') || (HTMLCS.util.colourStrToRGB(bgColour).alpha === 0)) {
                             if ((!parent) || (!parent.ownerDocument)) {
                                 break;
                             }
@@ -163,7 +163,7 @@ _global.HTMLCS_WCAG2AAA_Sniffs_Principle1_Guideline1_4_1_4_3_Contrast = {
                                 isAbsolute: true
                             });
                             continue;
-                        } else if ((bgColour === 'transparent') || (bgColour === 'rgba(0, 0, 0, 0)')) {
+                        } else if ((bgColour === 'transparent') || (HTMLCS.util.colourStrToRGB(bgColour).alpha === 0)) {
                             // If the background colour is still transparent, this is probably
                             // a fragment with which we cannot reliably make a statement about
                             // contrast ratio. Skip the element.
-- 
2.51.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions