Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A11y fixes for problem icons, including shape differentiation #2120

Merged
merged 8 commits into from
Apr 29, 2024
Merged
2 changes: 1 addition & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ApplicationHelper
def icon(id, label)
tag.i class: "bi bi-#{id}", role: "img", "aria-label": label, title: label
tag.i class: "bi bi-#{id}", role: "img", title: label
end

def card(style, title, options = {}, &content)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/models_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def group(files)
def status_badges(model)
badges = []
badges << content_tag(:span, icon("bi bi-stars", t("general.new")), class: "text-warning align-middle") if model.new?
badges << problem_icon(model.problems_including_files.visible(current_user.problem_settings))
badges << problem_icon_tag(model.problems_including_files.visible(current_user.problem_settings))
content_tag :span, safe_join(badges, " "), class: "status-badges"
end

Expand Down
18 changes: 15 additions & 3 deletions app/helpers/problems_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,25 @@ def problem_severity(problem)
end

def max_problem_severity(problems = Problem.all)
return nil if problems.empty?
severities = problems.select(:category).distinct.map { |p| problem_severity(p) }
severities.max_by { |p| Problem::SEVERITIES.find_index(p) }
end

def problem_icon(problems = Problem.all)
return "" if problems.empty?
def problem_icon(severity)
case severity
when :info
"info-circle-fill"
when :warning
"exclamation-triangle-fill"
when :danger
"x-octagon-fill"
end
end

def problem_icon_tag(problems = Problem.all)
severity = max_problem_severity(problems)
content_tag(:span, icon("exclamation-triangle-fill", Problem.model_name.human(count: 100)), class: "text-#{severity} align-middle")
ico = problem_icon(severity)
content_tag(:span, icon(ico, t("problems.severities.#{severity}")), class: "text-#{severity} align-middle") if ico # rubocop:todo I18n/RailsI18n/DecorateStringFormattingUsingInterpolation
end
end
6 changes: 4 additions & 2 deletions app/views/application/_navbar.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
<%- if current_user %>
<% if Problem.visible(current_user.problem_settings).count > 0 %>
<li class="nav-item">
<%= nav_link "exclamation-triangle-fill",
<% severity = max_problem_severity %>
<%= nav_link problem_icon(severity),
Problem.model_name.human(count: 100),
problems_path,
icon_style: "link-#{max_problem_severity}",
title: t("problems.severities.#{severity}"), # rubocop:todo I18n/RailsI18n/DecorateStringFormattingUsingInterpolation
icon_style: "link-#{severity}",
text_style: "d-lg-none" %>
</li>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<% end %>
<% if alert %>
<p class="alert alert-danger">
<%= icon "exclamation-triangle-fill", t(".alert.danger") %>
<%= icon "x-octagon-fill", t(".alert.danger") %>
<%= alert %>
</p>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/models/_file.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<% if file.presupported || file.presupported_version %>
<%= icon "bar-chart-line-fill", ModelFile.human_attribute_name(:presupported) %>
<% end %>
<%= problem_icon(file.problems) %>
<%= problem_icon_tag(file.problems) %>
</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
doc = Nokogiri::HTML(html)
expect(doc.at("i")["class"]).to eq("bi bi-test")
expect(doc.at("i")["role"]).to eq("img")
expect(doc.at("i")["aria-label"]).to eq("Test Label")
expect(doc.at("i")["title"]).to eq("Test Label")
end
end
Expand Down
Loading