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: 4 additions & 2 deletions src/core/structure.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,10 @@ function createTableOfContents(ol) {
}
}

const link = html`<p role="navigation" id="back-to-top">
<a href="#title"><abbr title="${l10n.back_to_top}">&uarr;</abbr></a>
const link = html`<p id="back-to-top">
<a href="#title"
><span aria-hidden="true">&uarr;</span> ${l10n.back_to_top}</a
>
</p>`;
document.body.append(link);
}
14 changes: 14 additions & 0 deletions src/styles/respec.css.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,24 @@ aside.example .marker > a.self-link {
}
}

#back-to-top {
text-align: end;
}

#back-to-top a {
display: inline-block;
padding: 0.5em 1em;
text-decoration: none;
}

@media print {
.removeOnSave {
display: none;
}

#back-to-top {
display: none;
}
}

/**
Expand Down
19 changes: 16 additions & 3 deletions tests/spec/core/structure-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,19 @@ describe("Core - Structure", () => {
expect(anchor).toBeTruthy();
});

it("does not use role=navigation and has accessible text for back to top link", async () => {
const ops = {
config: makeBasicConfig(),
body,
};
const doc = await makeRSDoc(ops);
const backToTop = doc.getElementById("back-to-top");
expect(backToTop).toBeTruthy();
expect(backToTop.getAttribute("role")).toBeNull();
const anchor = backToTop.querySelector("a");
expect(anchor.textContent.trim()).toContain("Back to Top");
});

it("localizes table of contents", async () => {
const ops = {
config: makeBasicConfig(),
Expand Down Expand Up @@ -352,9 +365,9 @@ describe("Core - Structure", () => {
};
const doc = await makeRSDoc(ops);
expect(doc.documentElement.lang).toBe("fr");
const abbr = doc.querySelector("#back-to-top abbr");
expect(abbr).toBeTruthy();
expect(abbr.title).toBe("Retourner en haut");
const link = doc.querySelector("#back-to-top a");
expect(link).toBeTruthy();
expect(link.textContent).toContain("Retourner en haut");
});

it("finds and updates empty anchors correctly", async () => {
Expand Down
Loading