Skip to content

Commit 46b1e38

Browse files
Change default background color to meet WCAG 2.2 contrast guidelines and add label for screen readers to radio box
1 parent a9d18e2 commit 46b1e38

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

jupyterquiz/dynamic/display.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def display_quiz(ref, num=1_000_000, shuffle_questions=False,
3232

3333
# Default color palette
3434
color_dict = {
35-
'--jq-multiple-choice-bg': '#6f78ffff',
35+
'--jq-multiple-choice-bg': '#392061',
3636
'--jq-mc-button-bg': '#fafafa',
3737
'--jq-mc-button-border': '#e0e0e0e0',
3838
'--jq-mc-button-inset-shadow': '#555555',

jupyterquiz/js/multiple_choice.js

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,31 +218,31 @@ function make_mc(qa, shuffle_answers, outerqDiv, qDiv, aDiv, id) {
218218
shuffled.forEach((item, index, ans_array) => {
219219
//console.log(answer);
220220

221+
// Make label for input element
222+
var lab = document.createElement("label");
223+
lab.className = "MCButton";
224+
lab.id = id + '-' + index;
225+
lab.onclick = check_mc;
226+
221227
// Make input element
222228
var inp = document.createElement("input");
223229
inp.type = "radio";
224230
inp.id = "quizo" + id + index;
225-
inp.style = "display:none;";
226-
aDiv.append(inp);
231+
inp.name = "mcgroup-" + id; // for grouping radios
232+
inp.className = "sr-only"; // or "visually-hidden" or whatever you call it
233+
234+
235+
lab.append(inp); // input is now inside the label
227236

228-
//Make label for input element
229-
var lab = document.createElement("label");
230-
lab.className = "MCButton";
231-
lab.id = id + '-' + index;
232-
lab.onclick = check_mc;
233237
var aSpan = document.createElement('span');
234-
aSpan.classsName = "";
235-
//qDiv.id="quizQn"+id+index;
236238
if ("answer" in item) {
237239
aSpan.innerHTML = jaxify(item.answer);
238-
//aSpan.innerHTML=item.answer;
239240
}
240241
lab.append(aSpan);
241242

242243
// Create div for code inside question
243-
var codeSpan;
244244
if ("code" in item) {
245-
codeSpan = document.createElement('span');
245+
var codeSpan = document.createElement('span');
246246
codeSpan.id = "code" + id + index;
247247
codeSpan.className = "QuizCode";
248248
var codePre = document.createElement('pre');
@@ -251,11 +251,8 @@ function make_mc(qa, shuffle_answers, outerqDiv, qDiv, aDiv, id) {
251251
codePre.append(codeCode);
252252
codeCode.innerHTML = item.code;
253253
lab.append(codeSpan);
254-
//console.log(codeSpan);
255254
}
256255

257-
//lab.textContent=item.answer;
258-
259256
// Set the data attributes for the answer
260257
lab.setAttribute('data-correct', item.correct);
261258
if (item.correct) {
@@ -266,8 +263,10 @@ function make_mc(qa, shuffle_answers, outerqDiv, qDiv, aDiv, id) {
266263
}
267264
lab.setAttribute('data-answered', 0);
268265

266+
// Only append the label (input is inside)
269267
aDiv.append(lab);
270268

269+
271270
});
272271

273272
if (num_correct > 1) {

0 commit comments

Comments
 (0)