Skip to content

Commit deb55d9

Browse files
authored
misc: fix docs accessibility (#1374)
1 parent 96a45e7 commit deb55d9

File tree

3 files changed

+14
-44
lines changed

3 files changed

+14
-44
lines changed

docs/dokka-presets/css/aws-styles.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@
5656
overflow-wrap: break-word;
5757
}
5858

59+
.keyValue {
60+
display: block;
61+
}
62+
5963
/*
6064
Disable the playground run button for generated samples
6165
https://github.com/Kotlin/dokka/issues/3041

docs/dokka-presets/scripts/accessibility.js

Lines changed: 9 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ if (document.readyState === "interactive" || document.readyState === "complete"
1717
* Fixes accessibility violation: "Provide a mechanism for skipping past repetitive content"
1818
*/
1919
function applySkipLinks() {
20+
document.querySelectorAll('#content').forEach(function(contentDiv) {
21+
contentDiv.setAttribute('role', 'main');
22+
contentDiv.setAttribute('tabindex', '-1');
23+
});
24+
2025
function insertSkipLink(element) {
2126
if (element.querySelectorAll(".skip-to-content").length > 0) { return }
2227

@@ -111,49 +116,9 @@ window.addEventListener('navigationLoaded', ensureNavButtonInteractable);
111116
* Fixes accessibility violation: "Ensure pages reflow without requiring two-dimensional scrolling without loss of content or functionality"
112117
*/
113118
function ensureContentReflow() {
114-
const MIN_WINDOW_SIZE = 550
115-
116-
// Function to insert 'toggle content' button
117-
function insertToggleContentButton(element) {
118-
if (element.parentNode.querySelectorAll(".aws-toggle-content-btn").length > 0) { return }
119-
120-
const initiallyVisible = window.innerWidth >= MIN_WINDOW_SIZE
121-
122-
const toggleContent = document.createElement('button');
123-
toggleContent.className = 'aws-toggle-content-btn';
124-
toggleContent.textContent = initiallyVisible ? '▼' : '▶'
125-
toggleContent.setAttribute('aria-expanded', initiallyVisible.toString());
126-
toggleContent.setAttribute('aria-label', 'Toggle code block for' + element.getAttribute("data-togglable"));
127-
toggleContent.setAttribute('aria-controls', element.id);
128-
129-
// Set initial visibility based on window size
130-
element.style.display = initiallyVisible ? 'block' : 'none'
131-
132-
// Toggle visibility onclick
133-
toggleContent.onclick = function() {
134-
const isExpanded = toggleContent.getAttribute('aria-expanded') === 'true';
135-
toggleContent.setAttribute('aria-expanded', (!isExpanded).toString());
136-
element.style.display = isExpanded ? 'none' : 'block'
137-
toggleContent.textContent = isExpanded ? '▶' : '▼'
138-
};
139-
140-
element.parentNode.insertBefore(toggleContent, element);
141-
}
142-
143-
document.querySelectorAll('.content[data-togglable]').forEach(insertToggleContentButton);
144-
145-
// Update content visibility on resize
146-
window.addEventListener('resize', function() {
147-
document.querySelectorAll('.content[data-togglable]').forEach(function(element) {
148-
const toggleContent = element.previousSibling;
149-
if (window.innerWidth < MIN_WINDOW_SIZE) {
150-
element.style.display = 'none';
151-
toggleContent.setAttribute('aria-expanded', 'false');
152-
} else {
153-
element.style.display = 'block';
154-
toggleContent.setAttribute('aria-expanded', 'true');
155-
}
156-
});
119+
// Ensure `content` sections are reflowable
120+
document.querySelectorAll('.content[data-togglable]').forEach(function(content) {
121+
content.style.display = 'block'
157122
});
158123
}
159-
window.addEventListener('navigationLoaded', ensureContentReflow);
124+
window.addEventListener('navigationLoaded', ensureContentReflow);

docs/dokka-presets/templates/base.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
<@header.display/>
3434
<div id="container">
3535
<div class="sidebar" id="leftColumn">
36+
<div><a class="skip-to-content" href="#content" tabindex="0">Skip to Main Content</a></div>
3637
<div class="sidebar--inner" id="sideMenu"></div>
3738
</div>
3839
<div id="main">

0 commit comments

Comments
 (0)