Add aria-pressed to in favor against component
In order to the users using screen readers know whether the button is pressed or not.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
class: "like #{voted_classes[:in_favor]}",
|
||||
title: t("votes.agree"),
|
||||
"aria-label": agree_aria_label,
|
||||
"aria-pressed": pressed?("yes"),
|
||||
method: "post",
|
||||
remote: true do %>
|
||||
<span class="show-for-sr"><%= t("votes.agree") %></span>
|
||||
@@ -16,6 +17,7 @@
|
||||
class: "unlike #{voted_classes[:against]}",
|
||||
title: t("votes.disagree"),
|
||||
"aria-label": disagree_aria_label,
|
||||
"aria-pressed": pressed?("no"),
|
||||
method: "post",
|
||||
remote: true do %>
|
||||
<span class="show-for-sr"><%= t("votes.disagree") %></span>
|
||||
|
||||
@@ -30,4 +30,15 @@ class Shared::InFavorAgainstComponent < ApplicationComponent
|
||||
def disagree_aria_label
|
||||
t("votes.disagree_label", title: votable.title)
|
||||
end
|
||||
|
||||
def pressed?(value)
|
||||
case current_user&.voted_as_when_voted_for(votable)
|
||||
when true
|
||||
value == "yes"
|
||||
when false
|
||||
value == "no"
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user