Skip to content

Commit 9fa5f12

Browse files
Stef-RoussetAyakorKalecslupu
authored
Fix Accessibility Like/Dislike Buttons on Comments (decidim#14837)
Co-authored-by: AyakorK <[email protected]> Co-authored-by: Alexandru Emil Lupu <[email protected]>
1 parent bb23516 commit 9fa5f12

File tree

1 file changed

+26
-7
lines changed

1 file changed

+26
-7
lines changed

decidim-comments/app/views/decidim/comments/votes/create.js.erb

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,30 @@
1313
$upVote.removeClass("is-vote-selected is-vote-notselected").removeAttr("disabled");
1414
$downVote.removeClass("is-vote-selected is-vote-notselected").removeAttr("disabled");
1515

16-
<% if comment.up_voted_by?(current_user) %>
17-
$upVote.addClass("is-vote-selected");
18-
$downVote.addClass("is-vote-notselected").attr("disabled", "disabled");
19-
<% elsif comment.down_voted_by?(current_user) %>
20-
$upVote.addClass("is-vote-notselected").attr("disabled", "disabled");
21-
$downVote.addClass("is-vote-selected");
22-
<% end %>
16+
function setVoteState($upVote, $downVote, isUpVoted, isDownVoted) {
17+
if (isUpVoted) {
18+
$upVote.addClass("is-vote-selected").attr("aria-pressed", "true");
19+
$downVote.addClass("is-vote-notselected").attr("aria-disabled", "true").attr("tabindex", "-1").removeAttr("disabled").css("cursor", "not-allowed");
20+
} else if (isDownVoted) {
21+
$upVote.addClass("is-vote-notselected").attr("aria-disabled", "true").attr("tabindex", "-1").removeAttr("disabled").css("cursor", "not-allowed");
22+
$downVote.addClass("is-vote-selected").attr("aria-pressed", "true");
23+
} else {
24+
$upVote.removeClass("is-vote-selected is-vote-notselected cursor-not-allowed").removeAttr("aria-pressed aria-disabled disabled tabindex").css("cursor", "");
25+
$downVote.removeClass("is-vote-selected is-vote-notselected cursor-not-allowed").removeAttr("aria-pressed aria-disabled disabled tabindex").css("cursor", "");
26+
}
27+
}
28+
29+
setVoteState($upVote, $downVote, <%= comment.up_voted_by?(current_user) %>, <%= comment.down_voted_by?(current_user) %>);
30+
31+
function handleAriaDisabledClick(e) {
32+
const $target = $(e.target).closest('[aria-disabled="true"]');
33+
if ($target.length > 0) {
34+
e.preventDefault();
35+
e.stopPropagation();
36+
e.stopImmediatePropagation();
37+
return false;
38+
}
39+
}
40+
41+
$(document).on('click mousedown', '[aria-disabled="true"]', handleAriaDisabledClick);
2342
}());

0 commit comments

Comments
 (0)