Use CSS to show separators in moderation actions

This is useful for people using screen readers, since the character used
as a separator won't be read aloud.

Since many screen readers also read content generated via CSS
pseudoelements, we aren't using `content: "|";` or similar but using
elements with a very small width instead.
This commit is contained in:
Javi Martín
2021-12-02 21:02:01 +01:00
parent a5c66c7281
commit 3b2b09be2b
4 changed files with 27 additions and 11 deletions

View File

@@ -7,4 +7,30 @@
button { button {
@include link; @include link;
} }
@mixin separator {
content: "";
display: inline-block;
margin: 0 0.3em;
vertical-align: middle;
}
> * + *::before {
@include separator;
background: currentcolor;
height: 1em;
opacity: 0.5;
width: 1px;
}
.comment & {
> *::before {
@include separator;
background: $text-light;
border-radius: 100%;
opacity: 1;
height: 0.25em;
width: 0.25em;
}
}
} }

View File

@@ -11,8 +11,6 @@
<% end %> <% end %>
<% if can? :hide, author %> <% if can? :hide, author %>
<%= raw separator %>
<%= render Admin::ActionComponent.new( <%= render Admin::ActionComponent.new(
:block_author, :block_author,
author, author,

View File

@@ -19,12 +19,4 @@ class Shared::ModerationActionsComponent < ApplicationComponent
def hide_path def hide_path
polymorphic_path([:moderation, record], action: :hide) polymorphic_path([:moderation, record], action: :hide)
end end
def separator
if record.is_a?(Comment)
"&nbsp;&bull;&nbsp;"
else
"&nbsp;|&nbsp;"
end
end
end end

View File

@@ -3,8 +3,8 @@
</span> </span>
<% if can?(:hide, comment) || can?(:hide, comment.user) %> <% if can?(:hide, comment) || can?(:hide, comment.user) %>
<span class="divider">&nbsp;&bull;&nbsp;</span>
<% if comment.author == current_user %> <% if comment.author == current_user %>
<span class="divider">&nbsp;&bull;&nbsp;</span>
<%= link_to t("comments.actions.delete"), <%= link_to t("comments.actions.delete"),
hide_comment_path(comment), hide_comment_path(comment),
method: :put, remote: true, class: "delete-comment", method: :put, remote: true, class: "delete-comment",