Skip to content

Commit

Permalink
Add target attribute for sending pagination events to LiveComponents
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinBoers committed Sep 2, 2023
1 parent 73e9ff4 commit 9db20da
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/petal_components/pagination.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule PetalComponents.Pagination do
doc:
"whether to use `phx-click` events instead of linking. Enabling this will disable `link_type` and `path`."

attr :target, :any, default: nil, doc: "the LiveView/LiveComponent to send the event to. Example: `@myself`."
attr :total_pages, :integer, default: nil, doc: "sets a total page count"
attr :current_page, :integer, default: nil, doc: "sets the current page"
attr :sibling_count, :integer, default: 1, doc: "sets a sibling count"
Expand All @@ -41,6 +42,7 @@ defmodule PetalComponents.Pagination do
<div>
<Link.a
phx-click={if @event, do: "goto-page"}
phx-target={@target}
phx-value-page={item.number}
link_type={if @event, do: "button", else: @link_type}
to={if not @event, do: get_path(@path, item.number, @current_page)}
Expand All @@ -58,6 +60,7 @@ defmodule PetalComponents.Pagination do
<% else %>
<Link.a
phx-click={if @event, do: "goto-page"}
phx-target={@target}
phx-value-page={item.number}
link_type={if @event, do: "button", else: @link_type}
to={if not @event, do: get_path(@path, item.number, @current_page)}
Expand All @@ -81,6 +84,7 @@ defmodule PetalComponents.Pagination do
<div>
<Link.a
phx-click={if @event, do: "goto-page"}
phx-target={@target}
phx-value-page={item.number}
link_type={if @event, do: "button", else: @link_type}
to={if not @event, do: get_path(@path, item.number, @current_page)}
Expand Down
3 changes: 2 additions & 1 deletion test/petal/dropdown_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ defmodule PetalComponents.DropdownTest do
""")

assert html =~ "pc-dropdown__menu-item--disabled"
assert html =~ " disabled" # the attribute itself
# the attribute itself
assert html =~ " disabled"
end

test "it works with a custom trigger" do
Expand Down

0 comments on commit 9db20da

Please sign in to comment.