Add aria-pressed to in comments votes component
In order to the users using screen readers know whether the button is pressed or not.
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<%= button_to vote_comment_path(comment, value: "yes"),
|
||||
method: "post",
|
||||
remote: can?(:vote, comment),
|
||||
"aria-pressed": pressed?("yes"),
|
||||
title: t("votes.agree") do %>
|
||||
<span class="show-for-sr"><%= t("votes.agree") %></span>
|
||||
<% end %>
|
||||
@@ -16,6 +17,7 @@
|
||||
<%= button_to vote_comment_path(comment, value: "no"),
|
||||
method: "post",
|
||||
remote: can?(:vote, comment),
|
||||
"aria-pressed": pressed?("no"),
|
||||
title: t("votes.disagree") do %>
|
||||
<span class="show-for-sr"><%= t("votes.disagree") %></span>
|
||||
<% end %>
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
class Comments::VotesComponent < ApplicationComponent
|
||||
attr_reader :comment
|
||||
delegate :can?, to: :helpers
|
||||
delegate :can?, :current_user, to: :helpers
|
||||
|
||||
def initialize(comment)
|
||||
@comment = comment
|
||||
end
|
||||
|
||||
def pressed?(value)
|
||||
case current_user&.voted_as_when_voted_for(comment)
|
||||
when true
|
||||
value == "yes"
|
||||
when false
|
||||
value == "no"
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user