Move result percentages out of the voting buttons

Having buttons (previously links) with the text "I agree 75%" is
confusing; people might believe they're saying they only partially agree
with the content. Besides, the results percentages is a different piece
of information which shouldn't be related to whether one person
agrees/disagrees with the content.

This problem might be solved for people using screen readers since we
added the aria-label attribute. However, for sighted keyboard users, the
percentage was being outlined on focus as part of the button, which
might be confusing.
This commit is contained in:
Javi Martín
2022-01-13 19:50:27 +01:00
parent 8c1b4d9ea7
commit eecaf5876e
4 changed files with 51 additions and 18 deletions

View File

@@ -1,5 +1,11 @@
.in-favor-against {
&,
.in-favor,
.against,
form {
display: inline-block;
}
.icon-like,
.icon-unlike {
@@ -41,9 +47,9 @@
.like,
.unlike {
line-height: rem-calc(48);
vertical-align: super;
text-decoration: none;
}
.percentage {
color: $text;
@@ -59,7 +65,6 @@
padding-right: 0;
}
}
}
.voted {

View File

@@ -1,5 +1,5 @@
<div class="in-favor-against">
<div class="in-favor inline-block">
<div class="in-favor">
<%= button_to polymorphic_path(votable, action: :vote, value: "yes"),
class: "like #{voted_classes[:in_favor]}",
title: t("votes.agree"),
@@ -10,13 +10,13 @@
<span class="icon-like">
<span class="show-for-sr"><%= t("votes.agree") %></span>
</span>
<span class="percentage"><%= votes_percentage("likes", votable) %></span>
<% end %>
<span class="percentage"><%= votes_percentage("likes", votable) %></span>
</div>
<span class="divider"></span>
<div class="against inline-block">
<div class="against">
<%= button_to polymorphic_path(votable, action: :vote, value: "no"),
class: "unlike #{voted_classes[:against]}",
title: t("votes.disagree"),
@@ -27,7 +27,7 @@
<span class="icon-unlike">
<span class="show-for-sr"><%= t("votes.disagree") %></span>
</span>
<span class="percentage"><%= votes_percentage("dislikes", votable) %></span>
<% end %>
<span class="percentage"><%= votes_percentage("dislikes", votable) %></span>
</div>
</div>

View File

@@ -25,5 +25,19 @@ describe Debates::VotesComponent do
expect(page).to have_button "I don't agree with What about the 2030 agenda?"
expect(page).not_to have_content "You must sign in or sign up to continue."
end
it "does not include result percentages" do
create(:vote, votable: debate)
sign_in(create(:user))
render_inline component
expect(page).to have_button count: 2
expect(page).to have_button "I agree"
expect(page).to have_button "I disagree"
expect(page).not_to have_button text: "%"
expect(page).not_to have_button text: "100"
expect(page).not_to have_button text: "0"
end
end
end

View File

@@ -38,5 +38,19 @@ describe Legislation::Proposals::VotesComponent do
expect(page).to have_button "I don't agree with Require wearing masks at home"
expect(page).not_to have_content "You must sign in or sign up to continue."
end
it "does not include result percentages" do
create(:vote, votable: proposal)
sign_in(create(:user))
render_inline component
expect(page).to have_button count: 2
expect(page).to have_button "I agree"
expect(page).to have_button "I disagree"
expect(page).not_to have_button text: "%"
expect(page).not_to have_button text: "100"
expect(page).not_to have_button text: "0"
end
end
end