fix: a11y low contrast in dark mode for code [AC-4348]#5777
fix: a11y low contrast in dark mode for code [AC-4348]#5777Stefan3002 wants to merge 1 commit intocanonical:mainfrom
Conversation
scss/_settings_colors.scss
Outdated
| $color-label-validated: #006b75; | ||
| $color-code-background: rgba($color-x-dark, 0.03); | ||
| $color-code-background-dark: rgba($color-x-light, 0.3); | ||
| $color-code-background-dark: rgba($color-x-light, 0.1); |
There was a problem hiding this comment.
While indeed the code text now has greater contrast against its own background, this also decreases the contrast between code and non-code text - it seems quite a bit harder to distinguish them.
Before
After
@juanruitina does this new background color look OK to you?
There was a problem hiding this comment.
It is more important to be able to read the text than to tell the semantics apart (and in this case, semantics are even reinforced by the monospace font). The contrast lower than 4.5 is not acceptable.
That said, @Stefan3002 it seems the case you are sharing in your screenshot is a corner case caused by the use of muted text. rgba($color-x-light, 0.15) would be sufficient to make the contrast greater than 4.5, see below. We could apply this to code tags only inside muted text, or for all code for the sake of simplicity and increased text contrast in all cases. Both options would be compliant.
Interestingly, this is not an issue in the light theme:
There was a problem hiding this comment.
Indeed, the problem is only present in dark mode 😄
fd1412b to
996a28e
Compare
|
Hey all, sorry for the huge delay. I was in medical leave unfortunately. Could I get another review on this please? 😄 |
996a28e to
86eb229
Compare
|
No worries, apologies for the delay also, I was on sick leave! I'll give it a look tomorrow :) |
| { | ||
| "name": "vanilla-framework", | ||
| "version": "4.47.0", | ||
| "version": "4.47.1", |
There was a problem hiding this comment.
4.47.0 hasn't been released yet - so doing this would actually skip 4.47.0 in the release order.
I'd recommend to keep this as 4.47.0
| "version": "4.47.1", | |
| "version": "4.47.0", |
| code { | ||
| background-color: rgba($color-x-light, 0.15); | ||
| } |
There was a problem hiding this comment.
This should be applied inside %muted-text placeholder, not the muted text class selector, so it applies to elements that extend %muted-text but don't have u-text--muted class (currently only notification timestamps).
| @extend %muted-text; | ||
|
|
||
| code { | ||
| background-color: rgba($color-x-light, 0.15); |
There was a problem hiding this comment.
$color-x-light is not color-theme sensitive. So, If you test this on light theme, the code background becomes indistinguishable from the background.
To solve this we'd need an opinion from design on what the right background color is for code inside muted text on light mode. But, @juanruitina mentioned this is fine, so I'm OK to leave this mostly as-is, but we should add a comment here explaining why we are using a non-themable variable here.
There was a problem hiding this comment.
Little misunderstanding. The quick fix I suggest is to apply the subtlier background of rgba(255, 255, 255, 0.15) to code blocks in the dark theme, regardless of muted or not. I think the proposed code instead targets muted code regardless of theme, resulting in a regression in the light theme.
For the record, I think I was looking at the live version, where there is such a distinction because of the use of var(--vf-color-background-code), rgba(0, 0, 0, 0.03 and should remain unchanged:
This is what it looks like in the demo (which is a regression):
There was a problem hiding this comment.
This PR produces no visual diffs because Vanilla has no examples that use code inside of muted text (I don't think Vanilla was aware of this as a use case). Could you add an example for Code that shows it inside an element with muted text? That way we can capture visual regressions of this use case in future.
It doesn't need to be shown on the docs page - just adding it to examples/ and the combined.html example for Code will cause it to be visually tested.
|
|
||
| code { |
There was a problem hiding this comment.
Explicitly targeting element tags causes a stylelint error (we try not to apply styles to tags unless we absolutely have to).
I think this is a valid use case for a tag selector though. To ignore the error and pass CI, see one of these examples to temporarily disable (then re-enable) this rule.
Done
codeelement in dark mode.QA
Look at a confirmation modal that says: Next time press SHIFT, the contrast of the SHIFT text should be increased and pass a11y guidelines
Check if PR is ready for release
If this PR contains Vanilla SCSS or macro code changes, it should contain the following changes to make sure it's ready for the release:
Feature 🎁,Breaking Change 💣,Bug 🐛,Documentation 📝,Maintenance 🔨.package.jsonshould be updated relative to the most recent release, following semver conventionFixes: AC-4348
Screenshots