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:
taitus
2023-05-29 10:49:16 +02:00
parent 7fd773773a
commit daf9692753
5 changed files with 67 additions and 28 deletions

View File

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

View File

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