Maturity: Developing
Usage
<.table id="pets" rows={@pets} caption="Pets">
<:col :let={p} label="name"><%= p.name %></:col>
<:col :let={p} label="age"><%= p.age %></:col>
</.table>
Row actions
row_click sets phx-click on each cell, which reaches pointer users only.
Where you use it, repeat the action as a link or button inside the row, so
that it can also be reached by keyboard.
<.table
id="pets"
rows={@pets}
caption="Pets"
row_click={&JS.navigate(~p"/pets/#{&1}")}
>
<:col :let={p} label="name">
<.link navigate={~p"/pets/#{p}"}><%= p.name %></.link>
</:col>
</.table>
Scroll container
The div around the table has tabindex="0", so that a table that is wider
than its container can be scrolled using the keyboard. This assumes that you
make the container scrollable:
.table-container {
overflow-x: auto;
}
Set caption or label to name the container, which is then exposed as a
region. A blank value counts as unset.
If the table fits its container, or sits in another scroll container, set
scrollable={false}. The wrapper then has no tabindex, no role and no
name, and does not add a useless tab stop.