From d53d87f1bcac10aef7f63cda47e3e7e6bcb6105e Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Tue, 18 Apr 2017 17:15:38 -0500 Subject: [PATCH] a11y polish --- .../javascripts/live-coder/editor.js.erb | 2 ++ app/views/quiz/_checkbox.html.erb | 14 +++++++---- app/views/quiz/_checkbox_other.html.erb | 12 ++++++---- app/views/quiz/_live_code.html.erb | 22 ++++++++--------- app/views/quiz/_radio.html.erb | 24 +++++++++++-------- app/views/quiz/_radio_other.html.erb | 13 ++++++---- app/views/quiz/_text.html.erb | 4 ++-- app/views/quiz/summary.html.erb | 6 ++--- test/integration/question_live_coder_test.rb | 2 +- 9 files changed, 59 insertions(+), 40 deletions(-) diff --git a/app/assets/javascripts/live-coder/editor.js.erb b/app/assets/javascripts/live-coder/editor.js.erb index 3f9652d..d9f918d 100644 --- a/app/assets/javascripts/live-coder/editor.js.erb +++ b/app/assets/javascripts/live-coder/editor.js.erb @@ -12,6 +12,7 @@ function updateResults(elem) { var iBody = document.createElement('body'); var codeFrame = document.createElement('iframe'); + codeFrame.setAttribute("title", "live-code-results-" + resultsContainer.getAttribute("data-qid")); codeFrame.setAttribute("width", "100%"); codeFrame.setAttribute("height", "100%"); resultsContainer.appendChild(codeFrame); @@ -27,6 +28,7 @@ function updateResults(elem) { codeStyle.appendChild(rulesNode); iHead.appendChild(codeStyle); + iDoc.setAttribute('lang', 'en'); iDoc.appendChild(iHead); iBody.innerHTML = codeHtml; iDoc.appendChild(iBody); diff --git a/app/views/quiz/_checkbox.html.erb b/app/views/quiz/_checkbox.html.erb index 030c526..f6d8b0c 100644 --- a/app/views/quiz/_checkbox.html.erb +++ b/app/views/quiz/_checkbox.html.erb @@ -1,14 +1,18 @@ -<% answers = Array(question.answer) %> -<%= form.collection_check_boxes(:answer_array, question.input_options, :to_s, :to_s, {}, {class: ""}) do | option | %> +<% answers = Array(question.answer) %> + +
+
Check all that apply:
+ <%= form.collection_check_boxes(:answer_array, question.input_options, :to_s, :to_s, {}, {class: ""}) do | option | %> <% option_id = "#{question.question_id}#{sanitize_to_id(option.value)}" checked = answers.include?(option.value) ? 'checked' : '' %> -
+
<%= option.check_box( id: option_id, checked: checked, data: { last: checked } ) %> - <%= option.label(for: option_id) %> + <%= option.label( for: option_id, "aria-label" => option_id ) %>
-<% end %> + <% end %> +
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %> diff --git a/app/views/quiz/_checkbox_other.html.erb b/app/views/quiz/_checkbox_other.html.erb index db6b4e1..fae8fd1 100644 --- a/app/views/quiz/_checkbox_other.html.erb +++ b/app/views/quiz/_checkbox_other.html.erb @@ -1,19 +1,22 @@ <% answers = question.answer.nil? ? [] : Array(question.answer['options']) other_value = question.answer.nil? ? '' : question.answer['other'] +%> +
+
Select all that apply:
- question.input_options.each do | option | + <% question.input_options.each do | option | option_id = "#{option.parameterize}_#{question.to_i}" checkbox_html = {class: "", id: option_id, data: { last: answers.include?(option) ? 'checked' : '' } } %> -
+
<%= check_box_tag('answer[answer_hash][options][]', option, answers.include?(option), checkbox_html) %> <%= label_tag(option_id, option) %>
<% end %> -
+
<% option_id = "other_#{question.to_i}" checkbox_html = {class: "", id: option_id, data: { last: answers.include?('other') ? 'checked' : '' } } @@ -21,7 +24,8 @@ %> <%= check_box_tag('answer[answer_hash][options][]', 'other', answers.include?('other'), checkbox_html) %> <%= label_tag(option_id, 'Other') %> - <%= text_field_tag 'answer[answer_hash][other]', other_value, text_html %> + <%= text_field_tag 'answer[answer_hash][other]', other_value, text_html.merge(id: "#{option_id}_value") %>
+
<%= render partial: "quiz/answer_errors", locals: {question: question, answer: answer} %> diff --git a/app/views/quiz/_live_code.html.erb b/app/views/quiz/_live_code.html.erb index cce5495..219923d 100644 --- a/app/views/quiz/_live_code.html.erb +++ b/app/views/quiz/_live_code.html.erb @@ -46,8 +46,8 @@