Skip to content

Commit 674e58e

Browse files
sorin-davidoiMichael-F-Bryan
authored andcommitted
fix(theme): Use aria-label alonside title (#568)
Tested this on macOS with VoiceOver, and it does not pick up the title as the text of the button. Kind of makes sense, since title and aria-label are not the same. This will make sure that the buttons and links are labeled properly.
1 parent 348c5d0 commit 674e58e

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/theme/book.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function playpen_text(playpen) {
172172

173173
var buttons = document.createElement('div');
174174
buttons.className = 'buttons';
175-
buttons.innerHTML = "<i class=\"fa fa-expand\" title=\"Show hidden lines\"></i>";
175+
buttons.innerHTML = "<button class=\"fa fa-expand\" title=\"Show hidden lines\" aria-label=\"Show hidden lines\"></button>";
176176

177177
// add expand button
178178
pre_block.prepend(buttons);
@@ -184,6 +184,7 @@ function playpen_text(playpen) {
184184
e.target.classList.remove('fa-expand');
185185
e.target.classList.add('fa-compress');
186186
e.target.title = 'Hide lines';
187+
e.target.setAttribute('aria-label', e.target.title);
187188

188189
Array.from(lines).forEach(function (line) {
189190
line.classList.remove('hidden');
@@ -195,6 +196,7 @@ function playpen_text(playpen) {
195196
e.target.classList.remove('fa-compress');
196197
e.target.classList.add('fa-expand');
197198
e.target.title = 'Show hidden lines';
199+
e.target.setAttribute('aria-label', e.target.title);
198200

199201
Array.from(lines).forEach(function (line) {
200202
line.classList.remove('unhidden');
@@ -217,6 +219,7 @@ function playpen_text(playpen) {
217219
var clipButton = document.createElement('button');
218220
clipButton.className = 'fa fa-copy clip-button';
219221
clipButton.title = 'Copy to clipboard';
222+
clipButton.setAttribute('aria-label', clipButton.title);
220223
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
221224

222225
buttons.prepend(clipButton);
@@ -237,11 +240,13 @@ function playpen_text(playpen) {
237240
runCodeButton.className = 'fa fa-play play-button';
238241
runCodeButton.hidden = true;
239242
runCodeButton.title = 'Run this code';
243+
runCodeButton.setAttribute('aria-label', runCodeButton.title);
240244

241245
var copyCodeClipboardButton = document.createElement('button');
242246
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
243247
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
244248
copyCodeClipboardButton.title = 'Copy to clipboard';
249+
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
245250

246251
buttons.prepend(runCodeButton);
247252
buttons.prepend(copyCodeClipboardButton);
@@ -255,6 +260,7 @@ function playpen_text(playpen) {
255260
var undoChangesButton = document.createElement('button');
256261
undoChangesButton.className = 'fa fa-history reset-button';
257262
undoChangesButton.title = 'Undo changes';
263+
undoChangesButton.setAttribute('aria-label', undoChangesButton.title);
258264

259265
buttons.prepend(undoChangesButton);
260266

src/theme/index.hbs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@
8989
<div id="menu-bar" class="menu-bar">
9090
<div id="menu-bar-sticky-container">
9191
<div class="left-buttons">
92-
<button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-controls="sidebar">
92+
<button id="sidebar-toggle" class="icon-button" type="button" title="Toggle Table of Contents" aria-label="Toggle Table of Contents" aria-controls="sidebar">
9393
<i class="fa fa-bars"></i>
9494
</button>
95-
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
95+
<button id="theme-toggle" class="icon-button" type="button" title="Change theme" aria-label="Change theme" aria-haspopup="true" aria-expanded="false" aria-controls="theme-list">
9696
<i class="fa fa-paint-brush"></i>
9797
</button>
9898
<ul id="theme-list" class="theme-popup" aria-label="submenu">
@@ -107,7 +107,7 @@
107107
<h1 class="menu-title">{{ book_title }}</h1>
108108

109109
<div class="right-buttons">
110-
<a href="print.html" title="Print this book">
110+
<a href="print.html" title="Print this book" aria-label="Print this book">
111111
<i id="print-button" class="fa fa-print"></i>
112112
</a>
113113
</div>
@@ -131,13 +131,13 @@
131131
<nav class="nav-wrapper" aria-label="Page navigation">
132132
<!-- Mobile navigation buttons -->
133133
{{#previous}}
134-
<a rel="prev" href="{{link}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-keyshortcuts="Left">
134+
<a rel="prev" href="{{link}}" class="mobile-nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
135135
<i class="fa fa-angle-left"></i>
136136
</a>
137137
{{/previous}}
138138

139139
{{#next}}
140-
<a rel="next" href="{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-keyshortcuts="Right">
140+
<a rel="next" href="{{link}}" class="mobile-nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
141141
<i class="fa fa-angle-right"></i>
142142
</a>
143143
{{/next}}
@@ -149,13 +149,13 @@
149149

150150
<nav class="nav-wide-wrapper" aria-label="Page navigation">
151151
{{#previous}}
152-
<a href="{{link}}" class="nav-chapters previous" title="Previous chapter" aria-keyshortcuts="Left">
152+
<a href="{{link}}" class="nav-chapters previous" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
153153
<i class="fa fa-angle-left"></i>
154154
</a>
155155
{{/previous}}
156156

157157
{{#next}}
158-
<a href="{{link}}" class="nav-chapters next" title="Next chapter" aria-keyshortcuts="Right">
158+
<a href="{{link}}" class="nav-chapters next" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
159159
<i class="fa fa-angle-right"></i>
160160
</a>
161161
{{/next}}

0 commit comments

Comments
 (0)