docs: formatting, docs and accessibility fix
This commit is contained in:
parent
d9e48a37d2
commit
c3502a326e
2 changed files with 26 additions and 35 deletions
|
|
@ -14,32 +14,29 @@ defmodule MvWeb.Components.SortHeaderComponent do
|
|||
{:ok, assign(socket, assigns)}
|
||||
end
|
||||
|
||||
# Check if we can add the aria-sort label directly to the daisyUI header
|
||||
# aria-sort={aria_sort(@field, @sort_field, @sort_order)}
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<button
|
||||
type="button"
|
||||
aria-sort={aria_sort(@field, @sort_field, @sort_order)}
|
||||
aria-label={aria_sort(@field, @sort_field, @sort_order)}
|
||||
class="btn btn-ghost select-none"
|
||||
phx-click="sort"
|
||||
phx-value-field={@field}
|
||||
phx-target={@myself}
|
||||
data-testid={@field}
|
||||
>
|
||||
{@label}
|
||||
<%= if @sort_field == @field do %>
|
||||
<.icon name={if @sort_order == :asc, do: "hero-chevron-up", else: "hero-chevron-down"} />
|
||||
<% else %>
|
||||
<.icon name="hero-chevron-up-down" class="opacity-40" />
|
||||
<.icon
|
||||
name="hero-chevron-up-down"
|
||||
class="opacity-40"
|
||||
/>
|
||||
<% end %>
|
||||
|
||||
<!-- Screen Reader Info -->
|
||||
<span class="sr-only">
|
||||
({if @sort_field == @field do
|
||||
if @sort_order == :asc, do: gettext("ascending"), else: gettext("descending")
|
||||
else
|
||||
gettext("not sorted")
|
||||
end})
|
||||
</span>
|
||||
</button>
|
||||
"""
|
||||
end
|
||||
|
|
@ -55,10 +52,10 @@ defmodule MvWeb.Components.SortHeaderComponent do
|
|||
# -------------------------------------------------
|
||||
defp aria_sort(field, sort_field, dir) when field == sort_field do
|
||||
case dir do
|
||||
:asc -> "ascending"
|
||||
:desc -> "descending"
|
||||
:asc -> gettext("ascending")
|
||||
:desc -> gettext("descending")
|
||||
end
|
||||
end
|
||||
|
||||
defp aria_sort(_, _, _), do: "none"
|
||||
defp aria_sort(_, _, _), do: gettext("Click to sort")
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue