feat: make checkbox column in member view sticky
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

This commit is contained in:
Simon 2026-05-08 11:37:04 +02:00
parent f3043df58b
commit 93e1ec7414
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
7 changed files with 234 additions and 35 deletions

View file

@ -9,7 +9,7 @@ defmodule MvWeb.Components.CoreComponentsTableTest do
alias MvWeb.CoreComponents
describe "table row_click styling" do
test "when row_click is set, table rows have hover and focus-within ring classes" do
test "when row_click is set, rows are marked interactive and omit ring hover classes" do
rows = [%{id: "1", name: "Alice"}, %{id: "2", name: "Bob"}]
assigns = %{
@ -31,12 +31,12 @@ defmodule MvWeb.Components.CoreComponentsTableTest do
html = render_component(&CoreComponents.table/1, assigns)
assert html =~ "hover:ring-2"
assert html =~ "focus-within:ring-2"
assert html =~ "hover:ring-base-content/10"
assert html =~ ~s(data-row-interactive="true")
refute html =~ "hover:ring-2"
refute html =~ "focus-within:ring-2"
end
test "when row_click is nil, table rows do not have hover ring classes" do
test "when row_click is nil, rows are not marked interactive" do
rows = [%{id: "1", name: "Alice"}]
assigns = %{
@ -58,8 +58,7 @@ defmodule MvWeb.Components.CoreComponentsTableTest do
html = render_component(&CoreComponents.table/1, assigns)
refute html =~ "hover:ring-2"
refute html =~ "focus-within:ring-2"
refute html =~ ~s(data-row-interactive="true")
end
end
@ -233,4 +232,101 @@ defmodule MvWeb.Components.CoreComponentsTableTest do
refute html =~ ~s(class="overflow-x-auto")
end
end
describe "sticky first column contract" do
test "when sticky_first_col is enabled, first header and body cells render sticky-left classes" do
rows = [%{id: "1", selected: true, name: "Alice"}]
assigns = %{
id: "test-table",
rows: rows,
row_id: fn r -> "row-#{r.id}" end,
row_click: nil,
sticky_first_col: true,
row_item: &Function.identity/1,
col: [
%{
__slot__: :col,
label: "Select",
inner_block: fn _socket, item -> [if(item[:selected], do: "x", else: "")] end
},
%{
__slot__: :col,
label: "Name",
inner_block: fn _socket, item -> [item[:name] || ""] end
}
],
dynamic_cols: [],
action: []
}
html = render_component(&CoreComponents.table/1, assigns)
assert html =~ "sticky"
assert html =~ "left-0"
assert html =~ "z-20"
assert html =~ "z-30"
end
test "sticky first column marks wrapper and uses CSS row backgrounds instead of row ring classes" do
rows = [%{id: "1", name: "Alice"}]
assigns = %{
id: "test-table",
rows: rows,
row_id: fn r -> "row-#{r.id}" end,
row_click: fn _ -> nil end,
sticky_first_col: true,
row_item: &Function.identity/1,
col: [
%{
__slot__: :col,
label: "Select",
inner_block: fn _socket, _item -> ["x"] end
},
%{
__slot__: :col,
label: "Name",
inner_block: fn _socket, item -> [item[:name] || ""] end
}
],
dynamic_cols: [],
action: []
}
html = render_component(&CoreComponents.table/1, assigns)
assert html =~ ~s(data-sticky-first-col-rows="true")
assert html =~ "sticky-first-col-cell"
refute html =~ "hover:ring-2"
end
test "sticky first column with selection sets data-selected without ring-primary" do
rows = [%{id: "one", name: "Alice"}, %{id: "two", name: "Bob"}]
assigns = %{
id: "test-table",
rows: rows,
row_id: fn r -> "row-#{r.id}" end,
row_click: fn _ -> nil end,
sticky_first_col: true,
selected_row_id: "two",
row_item: &Function.identity/1,
col: [
%{
__slot__: :col,
label: "Name",
inner_block: fn _socket, item -> [item[:name] || ""] end
}
],
dynamic_cols: [],
action: []
}
html = render_component(&CoreComponents.table/1, assigns)
assert html =~ ~s(data-selected="true")
refute html =~ "ring-primary"
end
end
end