-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Added a test for color contrast #2313
base: master
Are you sure you want to change the base?
Conversation
I added this to the 2.0 milestone. My thinking is these tests are a good idea, but we should bring the themes into compliance if we're going to add them (no good adding failing tests). Because these could be considered a breaking change (cuz these are changes in the theme), we could add the tests along with the (suggested or otherwise) color changes needed to bring them into compliance. |
v2.0 seems reasonable to me. A few themes (e.g. Solarized Light) have to be substantially changed in order to pass the tests. |
Great idea to improve contrast, looking forward to it. A suggestion: Consider aiming for a contrast ratio of 4.6 instead of 4.5, to avoid rounding errors that would make web browsers flag a color combination as low contrast. (It seems like Stack Overflow uses approx. 4.6 or higher for their syntax highlighting, for example). See the explanation in the first "Note" at this link (quoted below), which says 4.5 is a lower threshold, and computed values shouldn't be rounded up to 4.5:
I'm bringing this up because, in the "Details" dropdown of the original post, the first suggested color combination (#697988 on #FFFFFF) has a contrast ratio of 4.47 instead of 4.50 (maybe a rounding error?):
Here's a link to a contrast checker for this color combination. See screenshot below. Chrome dev tools also shows 4.47 for this color combination. |
Might be worth mentioning on the site which themes pass the contrast checks? |
I just noticed that for the twilight theme, |
This adds a new test to check the contrast of all colors against a background color.
It works via checking all
color
properties against a fixed background color which is set via a comment for the current scope. The background color can be set for a whole file or just a specific rule. The whole file is processed from top to bottom, so it's also possible to override a background color within the scope. Example:The actual color checking is implemented using color which conveniently can calculate the contrast for us and even supports LAB color mode.
For each low-contrast color, it will output the line of the low-contrast color, the contrast and a suggest color with the same hue but higher contrast (corrected in LAB color space). (See the
ensureContrast
function.)That being said: I'm not a designer and have no idea about color, so the correction might not be optimal.
I didn't fix any low-contrast colors as there are quite a few to fix.
Here's the current output of the test (only 2/8 themes pass):