Add aria-describedby attribute automatically

We were manually adding the attribute in many places, but not
everywhere. I'm assuming adding it where we didn't have it is doing no
harm.
This commit is contained in:
Javi Martín
2019-10-03 02:51:54 +02:00
parent 4a19bb6b77
commit 4f5de5be3b
10 changed files with 51 additions and 67 deletions

View File

@@ -64,10 +64,6 @@ module ProposalsHelper
proposals_current_view == "default" ? "minimal" : "default" proposals_current_view == "default" ? "minimal" : "default"
end end
def summary_help_text_id(translations_form)
"summary-help-text-#{translations_form.locale}"
end
def link_to_toggle_proposal_selection(proposal) def link_to_toggle_proposal_selection(proposal)
if proposal.selected? if proposal.selected?
button_text = t("admin.proposals.index.selected") button_text = t("admin.proposals.index.selected")

View File

@@ -22,16 +22,12 @@
maxlength: 8, maxlength: 8,
placeholder: t("admin.budget_headings.form.amount") %> placeholder: t("admin.budget_headings.form.amount") %>
<%= f.label :population, t("admin.budget_headings.form.population") %>
<p class="help-text" id="budgets-population-help-text">
<%= t("admin.budget_headings.form.population_info") %>
</p>
<%= f.text_field :population, <%= f.text_field :population,
label: false, label: t("admin.budget_headings.form.population"),
maxlength: 8, maxlength: 8,
placeholder: t("admin.budget_headings.form.population"), placeholder: t("admin.budget_headings.form.population"),
data: { toggle_focus: "population-info" }, data: { toggle_focus: "population-info" },
aria: { describedby: "budgets-population-help-text" } %> hint: t("admin.budget_headings.form.population_info") %>
<%= f.text_field :latitude, <%= f.text_field :latitude,
label: t("admin.budget_headings.form.latitude"), label: t("admin.budget_headings.form.latitude"),

View File

@@ -26,13 +26,10 @@
<%= f.invisible_captcha :subtitle %> <%= f.invisible_captcha :subtitle %>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :tag_list, t("debates.form.tags_label") %>
<p class="help-text" id="tag-list-help-text"><%= t("debates.form.tags_instructions") %></p>
<%= f.text_field :tag_list, value: @debate.tag_list.to_s, <%= f.text_field :tag_list, value: @debate.tag_list.to_s,
label: false, label: t("debates.form.tags_label"),
hint: t("debates.form.tags_instructions"),
placeholder: t("debates.form.tags_placeholder"), placeholder: t("debates.form.tags_placeholder"),
aria: { describedby: "tag-list-help-text" },
data: { js_url: suggest_tags_path }, data: { js_url: suggest_tags_path },
class: "tag-autocomplete" %> class: "tag-autocomplete" %>
</div> </div>

View File

@@ -14,11 +14,10 @@
<%= f.invisible_captcha :subtitle %> <%= f.invisible_captcha :subtitle %>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :summary, t("proposals.form.proposal_summary") %> <%= f.text_area :summary, rows: 4, maxlength: 200,
<p class="help-text" id="summary-help-text"><%= t("proposals.form.proposal_summary_note") %></p> label: t("proposals.form.proposal_summary"),
<%= f.text_area :summary, rows: 4, maxlength: 200, label: false,
placeholder: t("proposals.form.proposal_summary"), placeholder: t("proposals.form.proposal_summary"),
aria: { describedby: "summary-help-text" } %> hint: t("proposals.form.proposal_summary_note") %>
</div> </div>
<div class="ckeditor small-12 column"> <div class="ckeditor small-12 column">
@@ -29,10 +28,10 @@
</div> </div>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :video_url, t("proposals.form.proposal_video_url") %> <%= f.text_field :video_url,
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p> placeholder: t("proposals.form.proposal_video_url"),
<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), label: false, label: t("proposals.form.proposal_video_url"),
aria: { describedby: "video-url-help-text" } %> hint: t("proposals.form.proposal_video_url_note") %>
</div> </div>
<% if feature?(:allow_images) %> <% if feature?(:allow_images) %>

View File

@@ -8,11 +8,10 @@
<%= f.fields_for :organization do |fo| %> <%= f.fields_for :organization do |fo| %>
<%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("devise_views.organizations.registrations.new.organization_name_label") %> <%= fo.text_field :name, autofocus: true, maxlength: Organization.name_max_length, placeholder: t("devise_views.organizations.registrations.new.organization_name_label") %>
<%= fo.label :responsible_name %> <%= fo.text_field :responsible_name,
<p class="help-text" id="responsible-name-help-text"><%= t("devise_views.organizations.registrations.new.responsible_name_note") %></p> placeholder: t("devise_views.organizations.registrations.new.responsible_name_label"),
<%= fo.text_field :responsible_name, placeholder: t("devise_views.organizations.registrations.new.responsible_name_label"), maxlength: Organization.responsible_name_max_length,
maxlength: Organization.responsible_name_max_length, label: false, hint: t("devise_views.organizations.registrations.new.responsible_name_note") %>
aria: { describedby: "responsible-name-help-text" } %>
<% end %> <% end %>
<%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %> <%= f.email_field :email, placeholder: t("devise_views.organizations.registrations.new.email_label") %>

View File

@@ -17,15 +17,10 @@
<div class="js-suggest" data-locale="<%= translations_form.locale %>"></div> <div class="js-suggest" data-locale="<%= translations_form.locale %>"></div>
<div class="small-12 column"> <div class="small-12 column">
<%= translations_form.label :summary %>
<p class="help-text" id="<%= summary_help_text_id(translations_form) %>">
<%= t("proposals.form.proposal_summary_note") %>
</p>
<%= translations_form.text_area :summary, <%= translations_form.text_area :summary,
rows: 4, maxlength: 200, rows: 4, maxlength: 200,
label: false,
placeholder: t("proposals.form.proposal_summary"), placeholder: t("proposals.form.proposal_summary"),
aria: { describedby: summary_help_text_id(translations_form) } %> hint: t("proposals.form.proposal_summary_note") %>
</div> </div>
<div class="ckeditor small-12 column"> <div class="ckeditor small-12 column">
@@ -38,11 +33,9 @@
<%= f.invisible_captcha :subtitle %> <%= f.invisible_captcha :subtitle %>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :video_url, t("proposals.form.proposal_video_url") %>
<p class="help-text" id="video-url-help-text"><%= t("proposals.form.proposal_video_url_note") %></p>
<%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"), <%= f.text_field :video_url, placeholder: t("proposals.form.proposal_video_url"),
label: false, label: t("proposals.form.proposal_video_url"),
aria: { describedby: "video-url-help-text" } %> hint: t("proposals.form.proposal_video_url_note") %>
</div> </div>
<% if feature?(:allow_images) %> <% if feature?(:allow_images) %>
@@ -99,10 +92,10 @@
<% if current_user.unverified? %> <% if current_user.unverified? %>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :responsible_name, t("proposals.form.proposal_responsible_name") %> <%= f.text_field :responsible_name,
<p class="help-text" id="responsible-name-help-text"><%= t("proposals.form.proposal_responsible_name_note") %></p> placeholder: t("proposals.form.proposal_responsible_name"),
<%= f.text_field :responsible_name, placeholder: t("proposals.form.proposal_responsible_name"), label: false, label: t("proposals.form.proposal_responsible_name"),
aria: { describedby: "responsible-name-help-text" } %> hint: t("proposals.form.proposal_responsible_name_note") %>
</div> </div>
<% end %> <% end %>

View File

@@ -19,11 +19,11 @@
</div> </div>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :password, t("devise_views.users.registrations.edit.password_label") %> <%= f.password_field :password,
<p class="help-text" id="password-help-text"><%= t("devise_views.users.registrations.edit.leave_blank") %></p> autocomplete: "off",
<%= f.password_field :password, autocomplete: "off", label: false, label: t("devise_views.users.registrations.edit.password_label"),
placeholder: t("devise_views.users.registrations.edit.password_label"), placeholder: t("devise_views.users.registrations.edit.password_label"),
aria: { describedby: "password-help-text" } %> hint: t("devise_views.users.registrations.edit.leave_blank") %>
</div> </div>
<div class="small-12 column"> <div class="small-12 column">
@@ -34,11 +34,11 @@
</div> </div>
<div class="small-12 column"> <div class="small-12 column">
<%= f.label :current_password, t("devise_views.users.registrations.edit.current_password_label") %> <%= f.password_field :current_password,
<p class="help-text" id="current-password-help-text"><%= t("devise_views.users.registrations.edit.need_current") %></p> label: t("devise_views.users.registrations.edit.current_password_label"),
<%= f.password_field :current_password, label: false, autocomplete: "off", autocomplete: "off",
placeholder: t("devise_views.users.registrations.edit.current_password_label"), placeholder: t("devise_views.users.registrations.edit.current_password_label"),
aria: { describedby: "current-password-help-text" } %> hint: t("devise_views.users.registrations.edit.need_current") %>
</div> </div>
<div class="small-12 column"> <div class="small-12 column">

View File

@@ -17,12 +17,9 @@
<%= f.hidden_field :use_redeemable_code %> <%= f.hidden_field :use_redeemable_code %>
<%= f.hidden_field :locale, value: I18n.locale %> <%= f.hidden_field :locale, value: I18n.locale %>
<%= f.label :username %>
<p class="help-text" id="username-help-text"><%= t("devise_views.users.registrations.new.username_note") %></p>
<%= f.text_field :username, autofocus: true, maxlength: User.username_max_length, <%= f.text_field :username, autofocus: true, maxlength: User.username_max_length,
placeholder: t("devise_views.users.registrations.new.username_label"), placeholder: t("devise_views.users.registrations.new.username_label"),
label: false, hint: t("devise_views.users.registrations.new.username_note") %>
aria: { describedby: "username-help-text" } %>
<%= f.invisible_captcha :address %> <%= f.invisible_captcha :address %>

View File

@@ -71,11 +71,9 @@
</div> </div>
<div class="small-12 medium-5 clear"> <div class="small-12 medium-5 clear">
<%= f.label t("verification.residence.new.postal_code") %> <%= f.text_field :postal_code,
<p class="help-text" id="postal-code-help-text"><%= t("verification.residence.new.postal_code_note") %></p> label: t("verification.residence.new.postal_code"),
<div class="medium-6"> hint: t("verification.residence.new.postal_code_note") %>
<%= f.text_field :postal_code, label: false, aria: { describedby: "postal-code-help-text" } %>
</div>
</div> </div>
<div class="small-12"> <div class="small-12">

View File

@@ -10,7 +10,10 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
%i[text_field text_area cktext_area number_field password_field email_field].each do |field| %i[text_field text_area cktext_area number_field password_field email_field].each do |field|
define_method field do |attribute, options = {}| define_method field do |attribute, options = {}|
label_with_hint(attribute, options) + label_with_hint(attribute, options) +
super(attribute, options.merge(label: false, hint: false)) super(attribute, options.merge(
label: false, hint: false,
aria: { describedby: help_text_id(attribute, options) }
))
end end
end end
@@ -18,12 +21,18 @@ class ConsulFormBuilder < FoundationRailsHelper::FormBuilder
def label_with_hint(attribute, options) def label_with_hint(attribute, options)
custom_label(attribute, options[:label], options[:label_options]) + custom_label(attribute, options[:label], options[:label_options]) +
help_text(options[:hint]) help_text(attribute, options)
end end
def help_text(text) def help_text(attribute, options)
if text if options[:hint]
content_tag :span, text, class: "help-text" content_tag :span, options[:hint], class: "help-text", id: help_text_id(attribute, options)
end
end
def help_text_id(attribute, options)
if options[:hint]
"#{custom_label(attribute, nil, nil).match(/for=\"(.+)\"/)[1]}-help-text"
end end
end end
end end