Skip to content

Commit e740ab4

Browse files
Fix WCAG 2 AA color contrast issues in website navbar and HTML syntax highlighting (#5206)
* Initial plan * Fix WCAG 2 AA color contrast issues for navbar and HTML syntax highlighting Co-authored-by: hawkticehurst <39639992+hawkticehurst@users.noreply.github.com> * Fix code review issues: use WeakSet for theme tracking and update home page theme selector Co-authored-by: hawkticehurst <39639992+hawkticehurst@users.noreply.github.com> * Rename ACCESSIBLE_THEME_NAME to VS_LIGHT_ADJUSTED Co-authored-by: hawkticehurst <39639992+hawkticehurst@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: hawkticehurst <39639992+hawkticehurst@users.noreply.github.com>
1 parent fe9dd23 commit e740ab4

File tree

5 files changed

+48
-20
lines changed

5 files changed

+48
-20
lines changed

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/package-lock.json

Lines changed: 0 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

website/src/website/components/monaco/MonacoLoader.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,42 @@
11
import * as React from "react";
22
import { getMonaco, loadMonaco } from "../../../monaco-loader";
33

4+
// Name of the accessible theme for the website
5+
export const VS_LIGHT_ADJUSTED = "vs-accessible";
6+
7+
/**
8+
* Defines an accessible version of the VS theme with improved color contrast.
9+
* This theme fixes WCAG 2 AA color contrast issues with the default VS theme.
10+
* Uses a WeakSet to track Monaco instances to handle hot module reloading.
11+
*/
12+
const monacoInstancesWithTheme = new WeakSet<typeof globalThis.monaco>();
13+
14+
function defineAccessibleTheme(monaco: typeof globalThis.monaco): void {
15+
if (monacoInstancesWithTheme.has(monaco)) {
16+
return;
17+
}
18+
monacoInstancesWithTheme.add(monaco);
19+
20+
// Define an accessible VS theme with improved contrast ratios
21+
// The default VS theme uses #ff0000 for attribute.name which has insufficient
22+
// contrast (3.99:1) against white backgrounds. WCAG 2 AA requires 4.5:1.
23+
// #c50f1f provides ~4.71:1 contrast ratio against white.
24+
monaco.editor.defineTheme(VS_LIGHT_ADJUSTED, {
25+
base: "vs",
26+
inherit: true,
27+
rules: [
28+
// Fix attribute.name color for WCAG 2 AA compliance
29+
// #c50f1f on white gives ~4.71:1 contrast ratio (required: 4.5:1)
30+
{ token: "attribute.name", foreground: "c50f1f" },
31+
],
32+
colors: {},
33+
});
34+
35+
// Set the accessible theme as the default for the website
36+
// This ensures editors without an explicit theme use the accessible theme
37+
monaco.editor.setTheme(VS_LIGHT_ADJUSTED);
38+
}
39+
440
/**
541
* Can be used to render content only when monaco is loaded.
642
*/
@@ -13,10 +49,13 @@ export class MonacoLoader extends React.Component<
1349
this.state = { monaco: getMonaco() };
1450
if (!this.state.monaco) {
1551
loadMonaco().then((monaco) => {
52+
defineAccessibleTheme(monaco);
1653
this.setState({
1754
monaco,
1855
});
1956
});
57+
} else {
58+
defineAccessibleTheme(this.state.monaco);
2059
}
2160
}
2261
render() {

website/src/website/pages/home/Home.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
ControlledMonacoDiffEditor,
88
ControlledMonacoEditor,
99
} from "../../components/monaco/MonacoEditor";
10+
import { VS_LIGHT_ADJUSTED } from "../../components/monaco/MonacoLoader";
1011
import { ObservablePromise } from "../../utils/ObservablePromise";
1112
import * as React from "react";
1213
import { ref } from "../../utils/ref";
@@ -106,7 +107,7 @@ interface Theme {
106107
const themes: Theme[] = [
107108
{
108109
name: "Visual Studio",
109-
id: "vs",
110+
id: VS_LIGHT_ADJUSTED,
110111
},
111112
{
112113
name: "Visual Studio Dark",

website/src/website/style.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
.navbar {
22
background-color: #68217a !important;
3+
4+
// WCAG 2 AA compliant contrast for inactive nav links
5+
// #d4c4d9 on #68217a gives ~4.58:1 contrast ratio (required: 4.5:1)
6+
.nav-link:not(.active) {
7+
color: #d4c4d9 !important;
8+
}
39
}
410

511
.download-dropdown .dropdown-toggle::after {

0 commit comments

Comments
 (0)