Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/core/mdn-annotation.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ function findElements(data) {
*/
function getEngineSupportIcons(engines) {
if (engines.length === 3) {
return html`<span title="${l10n.inAllEngines}">✅</span>`;
return html`<span role="img" aria-label="${l10n.inAllEngines}">✅</span>`;
}
if (engines.length < 2) {
return html`<span title="${l10n.inSomeEngines}">🚫</span>`;
return html`<span role="img" aria-label="${l10n.inSomeEngines}">🚫</span>`;
}
return html`<span>&emsp;</span>`;
return html`<span aria-hidden="true" role="presentation">&emsp;</span>`;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/core/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const menu = html`<ul
const closeButton = html`<button
class="close-button"
onclick=${() => ui.closeModal()}
title="Close"
aria-label="Close"
>
</button>`;
Expand Down
16 changes: 13 additions & 3 deletions src/w3c/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,27 @@ export function run(conf) {
);
document.head.appendChild(colorScheme);
}
if (colorScheme?.content.includes("dark")) {
const darkModeStyleUrl = getStyleUrl("dark.css");
// Always add the dark stylesheet so fixup.js's updateTheme() can find it.
// For light-only specs, use disabled so it's present but never applied (#5200).
const darkModeStyleUrl = getStyleUrl("dark.css");
const isDark = colorScheme.content?.includes("dark") ?? false;
if (isDark) {
document.head.appendChild(
html`<link
rel="stylesheet"
href="${darkModeStyleUrl.href}"
media="(prefers-color-scheme: dark)"
/>`
);
// As required by W3C Pub Rules.
// As required by W3C Pub Rules, dark stylesheet must be last.
sub("beforesave", styleMover(darkModeStyleUrl));
} else {
const darkLink = html`<link
rel="stylesheet"
href="${darkModeStyleUrl.href}"
/>`;
darkLink.disabled = true;
document.head.appendChild(darkLink);
}
Comment thread
marcoscaceres marked this conversation as resolved.
}

Expand Down
6 changes: 4 additions & 2 deletions tests/spec/core/mdn-annotation-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ describe("Core - MDN Annotation", () => {
const iconBad = poorSupportedMdnPanel.querySelector(
"details summary span:nth-child(2)"
);
expect(iconBad.title).toContain("has limited support");
expect(iconBad.getAttribute("role")).toBe("img");
expect(iconBad.getAttribute("aria-label")).toContain("has limited support");
expect(iconBad.textContent).toBe("🚫");
const textBad = poorSupportedMdnPanel.querySelector("details p");
expect(textBad.classList).toContain("engines-some");
Expand All @@ -96,7 +97,8 @@ describe("Core - MDN Annotation", () => {
const iconGood = goodSupportedMdnPanel.querySelector(
"details summary span:nth-child(2)"
);
expect(iconGood.title).toContain("all major engines");
expect(iconGood.getAttribute("role")).toBe("img");
expect(iconGood.getAttribute("aria-label")).toContain("all major engines");
expect(iconGood.textContent).toBe("✅");
const textGood = goodSupportedMdnPanel.querySelector("details p");
expect(textGood.classList).toContain("engines-all");
Expand Down
13 changes: 13 additions & 0 deletions tests/spec/core/ui-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ describe("Core - UI", () => {
expect(window.getComputedStyle(menu).display).toBe("none");
});

it("close button has accessible label", async () => {
const doc = await makeRSDoc(makeStandardOps({ group: "webapps" }));
const ui = doc.defaultView.respecUI;
ui.freshModal(
"Test",
doc.createTextNode("content"),
doc.createElement("button")
);
const closeButton = doc.querySelector(".close-button");
expect(closeButton).toBeTruthy();
expect(closeButton.getAttribute("aria-label")).toBe("Close");
});

it("shows errors", async () => {
const doc = await makeRSDoc(makeStandardOps({ group: "webapps" }));
const ui = doc.defaultView.respecUI;
Expand Down
15 changes: 14 additions & 1 deletion tests/spec/w3c/style-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,27 @@ describe("W3C - Style", () => {
expect(elem.content).toBe("light");
});

it("always adds dark stylesheet link so fixup.js theme toggle works", async () => {
// Light-only specs must have dark.css link present so fixup.js updateTheme()
// doesn't throw a TypeError when accessing darkCss.disabled (issue #5200).
const ops = makeStandardOps(); // default: light-only color scheme
const doc = await makeRSDoc(ops);
const link = doc.querySelector(
`link[rel="stylesheet"][href="https://www.w3.org/StyleSheets/TR/2021/dark.css"]`
);
expect(link).toBeTruthy();
expect(link.disabled).toBeTrue();
});

it("adds dark mode stylesheet", async () => {
const ops = makeStandardOps();
const doc = await makeRSDoc(ops, "spec/core/color-scheme.html");
/** @type HTMLLinkElement? */
const link = doc.querySelector(
`link[href="https://www.w3.org/StyleSheets/TR/2021/dark.css"]`
`link[rel="stylesheet"][href="https://www.w3.org/StyleSheets/TR/2021/dark.css"]`
);
expect(link).toBeTruthy();
expect(link.getAttribute("media")).toBe("(prefers-color-scheme: dark)");
});

it("adds darkmode stylesheet at the end", async () => {
Expand Down
Loading