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:
taitus
2023-05-29 11:21:03 +02:00
parent 10cfa0e59f
commit 5009bf6c37
4 changed files with 71 additions and 3 deletions

View File

@@ -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 %>

View File

@@ -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