Skip to content

(enh) improve default theme accessibility #3402

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

Merged

Conversation

joshgoebel
Copy link
Member

@joshgoebel joshgoebel commented Nov 16, 2021

Resolves #3393.

  • first pass at accessibility report in checkTheme
  • resolve CSS color names when necessary
  • (enh) default Dark theme is WCAG AAA wrt contrast

Changes

Dark Theme

Accessibility Report
┌───────┬────────────────────────────────────────┬──────────┬──────────┐
│ ratio │ selector                               │ fg       │ bg       │
│ 9.72  │ .hljs                                  │ #ddd     │ #303030  │
│ 13.2  │ .hljs-keyword,.hljs-selector-tag,.hlj… │ #ffffff  │ #303030  │
│ 5     │ .hljs-string,.hljs-title,.hljs-name,.… │ #d88     │ #303030  │
│ 4.52  │ .hljs-comment,.hljs-quote,.hljs-delet… │ #979797  │ #303030  │
└───────┴────────────────────────────────────────┴──────────┴──────────┘

Light Theme

Accessibility Report
┌───────┬────────────────────────────────────────┬──────────┬──────────┐
│ ratio │ selector                               │ fg       │ bg       │
│ 8.78  │ .hljs                                  │ #444     │ #F3F3F3  │
│ 4.56  │ .hljs-comment                          │ #697070  │ #F3F3F3  │
│ 8.78  │ .hljs-tag,.hljs-punctuation            │ #444a    │ #F3F3F3  │
│ 8.78  │ .hljs-tag .hljs-name,.hljs-tag .hljs-… │ #444     │ #F3F3F3  │
│ 9.25  │ .hljs-type,.hljs-string,.hljs-number,… │ #880000  │ #F3F3F3  │
│ 9.25  │ .hljs-title,.hljs-section              │ #880000  │ #F3F3F3  │
│ 4.51  │ .hljs-regexp,.hljs-symbol,.hljs-varia… │ #ab5656  │ #F3F3F3  │
│ 3.03  │ .hljs-literal                          │ #695     │ #F3F3F3  │
│ 5.22  │ .hljs-built_in,.hljs-bullet,.hljs-cod… │ #397300  │ #F3F3F3  │
│ 4.88  │ .hljs-meta                             │ #1f7199  │ #F3F3F3  │
│ 3.61  │ .hljs-meta .hljs-string                │ #38a     │ #F3F3F3  │
└───────┴────────────────────────────────────────┴──────────┴──────────┘

Checklist

  • Added markup tests, or they don't apply here because...
  • Updated the changelog at CHANGES.md

@joshgoebel joshgoebel force-pushed the accessibility_default_themes branch from e0c83ca to ef08f0b Compare November 16, 2021 13:01
@joshgoebel joshgoebel force-pushed the accessibility_default_themes branch from ef08f0b to 6865cb7 Compare November 16, 2021 17:16
@joshgoebel joshgoebel requested a review from allejo December 6, 2021 21:24
Copy link
Member

@allejo allejo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I dealt with this in highlight.php, just some nitpicks if we want this tool to be robust enough to scan all of our themes.

function contrast_report(rules) {
console.log("Accessibility Report".yellow);

var hljs = rules.find (x => x.selectors && x.selectors.includes(".hljs"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var hljs = rules.find (x => x.selectors && x.selectors.includes(".hljs"));
var hljs = rules.find(x => x.selectors?.includes(".hljs"));

nitpick

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you point out this isn't supported everywhere so I'm going to slow down with it until we figure our how/where to specify that dev work requires newer versions...

Comment on lines +200 to +201
this.bg = rule.declarations.find(x => x.property =="background")?.value;
this.fg = rule.declarations.find(x => x.property =="color")?.value;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two notes on this one:

  1. Some styles use background-color to differentiate the background for specific elements. I think we should add support for checking background-color for WCAG contrast.

    .hljs-regexp {
    background-color: #fff0ff;
    color: #880088;
    }

  2. Should we have a minimum Node defined somewhere for dev environments? Optional chaining was added in Node 14 and our package.json requires Node 12+ (correctly so, for our users).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we have a minimum Node defined somewhere for dev environments?

Ah, we probably should, but where... damn old versions of Node. :-)

Some styles use background-color

I'll break this out into a separate issue... the tool doesn't have to be perfect for the main thrust of this to be mergeable.

contrastRatio() {
if (!this.foreground) return "unknown (no fg)"
if (!this.background) return "unknown(no bg)"
return round2(wcagContrast.hex(this.foreground, this.background));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some themes that use rgba(), will .hex() work on those values?

.hljs-comment {
color: rgba(149,165,166,.8);
}

joshgoebel and others added 2 commits December 9, 2021 10:41
Co-authored-by: Vladimir Jimenez <allejo@me.com>
Co-authored-by: Vladimir Jimenez <allejo@me.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve accessibility (slightly) of default light and dark themes
2 participants