feat: add col_click attribute to table component for checkbox column

- Add col_click slot attribute to table component that overrides row_click
- Clicking anywhere in the checkbox column now toggles the checkbox
- Clicking other columns still navigates to member details

Closes #223
This commit is contained in:
Moritz 2025-12-03 14:24:10 +01:00
parent 09c75212b2
commit 8e4f1ba674
6 changed files with 71 additions and 60 deletions

View file

@ -357,6 +357,7 @@ defmodule MvWeb.CoreComponents do
slot :col, required: true do
attr :label, :string
attr :col_click, :any, doc: "optional column-specific click handler that overrides row_click"
end
slot :action, doc: "the slot for showing user actions in the last table column"
@ -391,8 +392,11 @@ defmodule MvWeb.CoreComponents do
<tr :for={row <- @rows} id={@row_id && @row_id.(row)}>
<td
:for={col <- @col}
phx-click={@row_click && @row_click.(row)}
class={@row_click && "hover:cursor-pointer"}
phx-click={
(col[:col_click] && col[:col_click].(@row_item.(row))) ||
(@row_click && @row_click.(row))
}
class={(col[:col_click] || @row_click) && "hover:cursor-pointer"}
>
{render_slot(col, @row_item.(row))}
</td>