Skip to content
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

ContrastChecker component doesn't process CSS variables #20508

Open
goldenapples opened this issue Feb 27, 2020 · 1 comment
Open

ContrastChecker component doesn't process CSS variables #20508

goldenapples opened this issue Feb 27, 2020 · 1 comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Enhancement A suggestion for improvement.

Comments

@goldenapples
Copy link

Describe the bug
It's possible to register an editor color palette using CSS variables as colors, like this:

add_theme_support(
    'editor-color-palette', [
        [
            'name' => 'Black',
            'slug' => 'black',
            'color' => 'var( --black )',
        ],
        [
            'name' => 'Red',
            'slug' => 'red',
            'color' => 'var( --red )',
        ],
        [
            'name' => 'White',
            'slug' => 'white',
            'color' => 'var( --white )',
        ],
    ]
);

However, no matter what the CSS variable is defined as, the contrast checker message displays "This color combination may be hard for people to read. Try using a darker background color and/or a brighter text color.".

Expected behavior
I believe this is happening because tinycolor2 evaluates any unrecognized color format as black. It would be better, in cases like this where tinycolor doesn't recognize the color format, to fall back to the detected color from getComputedStyle(), which can properly return the value of the CSS variable.

Desktop (please complete the following information):

  • OS: OSX
  • Browser Chrome
  • Version 80.0.3987.116

Additional context
I tested using the block editor from core 5.3.2, and also using the latest plugin release 7.6.0.

@talldan
Copy link
Contributor

talldan commented Mar 3, 2020

@goldenapples I think it's likely that the color palette wasn't designed to work with css variables (judging by the docs - https://developer.wordpress.org/block-editor/developers/themes/theme-support/#block-color-palettes), so I'm not sure this could be considered a bug, I'll label as an enhancement.

@talldan talldan added [a11y] Color Contrast [Type] Enhancement A suggestion for improvement. [Feature] Themes Questions or issues with incorporating or styling blocks in a theme. labels Mar 3, 2020
@skorasaurus skorasaurus added the [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). label Jul 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Themes Questions or issues with incorporating or styling blocks in a theme. [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

4 participants