Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flop.Phoenix.pagination change to allow not to render next/prev links #270

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/flop_phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ defmodule Flop.Phoenix do
Default: `#{inspect(Pagination.default_opts()[:wrapper_attrs])}`.
"""
@type pagination_option ::
{:current_link_attrs, keyword}
{:render_next_and_previous_links, boolean()}
| {:current_link_attrs, keyword}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Little nitpick, the options here are in alphabetical order, can you move the new option to the right position?

| {:disabled_class, String.t()}
| {:ellipsis_attrs, keyword}
| {:ellipsis_content, Phoenix.HTML.safe() | binary}
Expand Down Expand Up @@ -429,6 +430,7 @@ defmodule Flop.Phoenix do
~H"""
<nav :if={@meta.errors == [] && @meta.total_pages > 1} {@opts[:wrapper_attrs]}>
<.pagination_link
:if={@opts[:render_next_and_previous_links]}
disabled={[email protected]_previous_page?}
disabled_class={@opts[:disabled_class]}
event={@event}
Expand All @@ -441,6 +443,7 @@ defmodule Flop.Phoenix do
<%= @opts[:previous_link_content] %>
</.pagination_link>
<.pagination_link
:if={@opts[:render_next_and_previous_links]}
disabled={[email protected]_next_page?}
disabled_class={@opts[:disabled_class]}
event={@event}
Expand Down
1 change: 1 addition & 0 deletions lib/flop_phoenix/pagination.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ defmodule Flop.Phoenix.Pagination do
@spec default_opts() :: [Flop.Phoenix.pagination_option()]
def default_opts do
[
render_next_and_previous_links: true,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list is alphabetically sorted as well. 🔤

current_link_attrs: [
class: "pagination-link is-current",
aria: [current: "page"]
Expand Down
19 changes: 17 additions & 2 deletions test/flop_phoenix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ defmodule Flop.PhoenixTest do
""") == []
end

test "does not render next and previous links if user specifies not to" do
assigns = %{meta: build(:meta_on_first_page)}

html =
parse_heex(~H"""
<Flop.Phoenix.pagination
meta={@meta}
on_paginate={%JS{}}
opts={[render_next_and_previous_links: false]}
/>
""")

assert [] = Floki.find(html, ".pagination-next")
assert [] = Floki.find(html, ".pagination-previous")
end

test "allows to overwrite wrapper class" do
assigns = %{meta: build(:meta_on_first_page)}

Expand Down Expand Up @@ -3023,8 +3039,7 @@ defmodule Flop.PhoenixTest do
assert [
{"div", [{"data-test-id", "thead-label-component"}],
["\n Custom\n"]}
] =
Floki.find(html, ~s([data-test-id="thead-label-component"]))
] = Floki.find(html, ~s([data-test-id="thead-label-component"]))
end

test "renders multiple inputs for the same field", %{
Expand Down
Loading