Skip to content

Commit

Permalink
Merge pull request #280 from woylie/fix/missing-li
Browse files Browse the repository at this point in the history
fix: wrap links to first and last page in li as well
  • Loading branch information
woylie authored Oct 19, 2023
2 parents 827ad51 + 7df1fd7 commit 7da3392
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 55 deletions.
48 changes: 26 additions & 22 deletions lib/flop_phoenix.ex
Original file line number Diff line number Diff line change
Expand Up @@ -487,17 +487,19 @@ defmodule Flop.Phoenix do

~H"""
<ul :if={@opts[:page_links] != :hide} {@opts[:pagination_list_attrs]}>
<.pagination_link
:if={@first > 1}
event={@event}
target={@target}
page={1}
path={@page_link_helper.(1)}
on_paginate={@on_paginate}
{Pagination.attrs_for_page_link(1, @meta, @opts)}
>
1
</.pagination_link>
<li>
<.pagination_link
:if={@first > 1}
event={@event}
target={@target}
page={1}
path={@page_link_helper.(1)}
on_paginate={@on_paginate}
{Pagination.attrs_for_page_link(1, @meta, @opts)}
>
1
</.pagination_link>
</li>
<li :if={@first > 2}>
<span {@opts[:ellipsis_attrs]}><%= @opts[:ellipsis_content] %></span>
Expand All @@ -520,17 +522,19 @@ defmodule Flop.Phoenix do
<span {@opts[:ellipsis_attrs]}><%= @opts[:ellipsis_content] %></span>
</li>
<.pagination_link
:if={@last < @meta.total_pages}
event={@event}
target={@target}
page={@meta.total_pages}
path={@page_link_helper.(@meta.total_pages)}
on_paginate={@on_paginate}
{Pagination.attrs_for_page_link(@meta.total_pages, @meta, @opts)}
>
<%= @meta.total_pages %>
</.pagination_link>
<li>
<.pagination_link
:if={@last < @meta.total_pages}
event={@event}
target={@target}
page={@meta.total_pages}
path={@page_link_helper.(@meta.total_pages)}
on_paginate={@on_paginate}
{Pagination.attrs_for_page_link(@meta.total_pages, @meta, @opts)}
>
<%= @meta.total_pages %>
</.pagination_link>
</li>
</ul>
"""
end
Expand Down
6 changes: 3 additions & 3 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"credo": {:hex, :credo, "1.7.1", "6e26bbcc9e22eefbff7e43188e69924e78818e2fe6282487d0703652bc20fd62", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "e9871c6095a4c0381c89b6aa98bc6260a8ba6addccf7f6a53da8849c748a58a2"},
"decimal": {:hex, :decimal, "2.1.1", "5611dca5d4b2c3dd497dec8f68751f1f1a54755e8ed2a966c2633cf885973ad6", [:mix], [], "hexpm", "53cfe5f497ed0e7771ae1a475575603d77425099ba5faef9394932b35020ffcc"},
"dialyxir": {:hex, :dialyxir, "1.4.1", "a22ed1e7bd3a3e3f197b68d806ef66acb61ee8f57b3ac85fc5d57354c5482a93", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "84b795d6d7796297cca5a3118444b80c7d94f7ce247d49886e7c291e1ae49801"},
"earmark_parser": {:hex, :earmark_parser, "1.4.33", "3c3fd9673bb5dcc9edc28dd90f50c87ce506d1f71b70e3de69aa8154bc695d44", [:mix], [], "hexpm", "2d526833729b59b9fdb85785078697c72ac5e5066350663e5be6a1182da61b8f"},
"earmark_parser": {:hex, :earmark_parser, "1.4.37", "2ad73550e27c8946648b06905a57e4d454e4d7229c2dafa72a0348c99d8be5f7", [:mix], [], "hexpm", "6b19783f2802f039806f375610faa22da130b8edc21209d0bff47918bb48360e"},
"ecto": {:hex, :ecto, "3.10.3", "eb2ae2eecd210b4eb8bece1217b297ad4ff824b4384c0e3fdd28aaf96edd6135", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "44bec74e2364d491d70f7e42cd0d690922659d329f6465e89feb8a34e8cd3433"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.30.6", "5f8b54854b240a2b55c9734c4b1d0dd7bdd41f71a095d42a70445c03cf05a281", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bd48f2ddacf4e482c727f9293d9498e0881597eae6ddc3d9562bd7923375109f"},
"ex_doc": {:hex, :ex_doc, "0.30.8", "cf3eb2eb32137966aab0929bb3af42773b2d08e2f785a5fee9caabf664082cb3", [:mix], [{:earmark_parser, "~> 1.4.31", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "bfb981d8e0a8ab23857e502d611c612ae2c24536dd3b530e741d1d94ea44e6e2"},
"ex_machina": {:hex, :ex_machina, "2.7.0", "b792cc3127fd0680fecdb6299235b4727a4944a09ff0fa904cc639272cd92dc7", [:mix], [{:ecto, "~> 2.2 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: true]}], "hexpm", "419aa7a39bde11894c87a615c4ecaa52d8f107bbdd81d810465186f783245bf8"},
"excoveralls": {:hex, :excoveralls, "0.18.0", "b92497e69465dc51bc37a6422226ee690ab437e4c06877e836f1c18daeb35da9", [:mix], [{:castore, "~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "1109bb911f3cb583401760be49c02cbbd16aed66ea9509fc5479335d284da60b"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"floki": {:hex, :floki, "0.35.0", "b24a4f416738d08e468531fe2950305a2c0582f555992dfbefc925462d24e2ea", [:mix], [], "hexpm", "381d8030f708be55380de1202872172600b00d65a62072f0e5eda5976b9de7b4"},
"floki": {:hex, :floki, "0.35.1", "b21cf592ed38c1207c5ea52120a2e81d6ecba11337a633a3f29ec17a64033178", [:mix], [], "hexpm", "f126e3eb814f131c21befeeeb773d2c4e2331ce05214c1a9844a3edde5c69003"},
"flop": {:hex, :flop, "0.23.0", "68b07840df6dc6fc53682097f3838c8ea5b6806642c41651a2d5da85f7e676b1", [:mix], [{:ecto, "~> 3.10.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:nimble_options, "~> 1.0", [hex: :nimble_options, repo: "hexpm", optional: false]}], "hexpm", "0521d0cbd58433607b9e9c77e065cc00eeb6ffdacd8fa1ed009366386f72d6c0"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.0", "6b67c8bc2882a6b6a445859952a602afc1a41c2e08379ca057c0f525366fc3ca", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "0a45ed501f4a8897f580eabf99a2e5234ea3e75a4373c8a52824f6e873be57a6"},
Expand Down
60 changes: 30 additions & 30 deletions test/flop_phoenix_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ defmodule Flop.PhoenixTest do
<Flop.Phoenix.pagination meta={@meta} event="paginate" />
""")

assert [link] = Floki.find(html, "a[aria-label='Go to page 1']")
assert [link] = Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.attribute(link, "href") == ["#"]
assert Floki.attribute(link, "phx-click") == ["paginate"]
assert Floki.attribute(link, "phx-value-page") == ["1"]
Expand All @@ -559,7 +559,7 @@ defmodule Flop.PhoenixTest do
<Flop.Phoenix.pagination meta={@meta} event="paginate" target="here" />
""")

assert [link] = Floki.find(html, "a[aria-label='Go to page 1']")
assert [link] = Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.attribute(link, "phx-target") == ["here"]
end

Expand Down Expand Up @@ -617,12 +617,12 @@ defmodule Flop.PhoenixTest do
/>
""")

assert [link] = Floki.find(html, "a[aria-label='Go to page 1']")
assert [link] = Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.attribute(link, "beep") == ["boop"]
assert Floki.attribute(link, "class") == ["p-link"]

# current link attributes are unchanged
assert [link] = Floki.find(html, "a[aria-label='Go to page 2']")
assert [link] = Floki.find(html, "li a[aria-label='Go to page 2']")
assert Floki.attribute(link, "beep") == []
assert Floki.attribute(link, "class") == ["pagination-link is-current"]
end
Expand All @@ -639,14 +639,14 @@ defmodule Flop.PhoenixTest do
/>
""")

assert [link] = Floki.find(html, "a[aria-label='Go to page 1']")
assert [link] = Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.attribute(link, "class") == ["pagination-link"]
assert Floki.attribute(link, "data-phx-link") == ["patch"]
assert Floki.attribute(link, "data-phx-link-state") == ["push"]
assert Floki.attribute(link, "href") == ["/pets?page_size=10"]
assert String.trim(Floki.text(link)) == "1"

assert [link] = Floki.find(html, "a[aria-label='Go to page 2']")
assert [link] = Floki.find(html, "li a[aria-label='Go to page 2']")
assert Floki.attribute(link, "beep") == ["boop"]
assert Floki.attribute(link, "class") == ["link is-active"]
assert Floki.attribute(link, "data-phx-link") == ["patch"]
Expand Down Expand Up @@ -721,7 +721,7 @@ defmodule Flop.PhoenixTest do
assert [href] = Floki.attribute(previous, "href")
assert_urls_match(href, "/pets", expected_query.(1))

assert [one] = Floki.find(html, "a[aria-label='Go to page 1']")
assert [one] = Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.attribute(one, "class") == ["pagination-link"]
assert Floki.attribute(one, "data-phx-link") == ["patch"]
assert Floki.attribute(one, "data-phx-link-state") == ["push"]
Expand Down Expand Up @@ -842,7 +842,7 @@ defmodule Flop.PhoenixTest do
assert [href] = Floki.attribute(previous, "href")
assert_urls_match(href, "/pets", expected_query.(1))

assert [one] = Floki.find(html, "a[aria-label='Go to page 1']")
assert [one] = Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.attribute(one, "class") == ["pagination-link"]
assert Floki.attribute(one, "data-phx-link") == ["patch"]
assert Floki.attribute(one, "data-phx-link-state") == ["push"]
Expand Down Expand Up @@ -898,13 +898,13 @@ defmodule Flop.PhoenixTest do
<Flop.Phoenix.pagination meta={@meta} path="/pets" opts={@opts} />
""")

assert html |> Floki.find(".pagination-ellipsis") |> length() == 1
assert html |> Floki.find(".pagination-link") |> length() == 6
assert html |> Floki.find("li .pagination-ellipsis") |> length() == 1
assert html |> Floki.find("li .pagination-link") |> length() == 6

assert Floki.find(html, "a[aria-label='Go to page 20']")
assert Floki.find(html, "li a[aria-label='Go to page 20']")

for i <- 1..5 do
assert Floki.find(html, "a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand All @@ -922,10 +922,10 @@ defmodule Flop.PhoenixTest do
assert html |> Floki.find(".pagination-ellipsis") |> length() == 1
assert html |> Floki.find(".pagination-link") |> length() == 6

assert Floki.find(html, "a[aria-label='Go to page 1']")
assert Floki.find(html, "li a[aria-label='Go to page 1']")

for i <- 16..20 do
assert Floki.find(html, "a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand All @@ -943,11 +943,11 @@ defmodule Flop.PhoenixTest do
assert html |> Floki.find(".pagination-ellipsis") |> length() == 2
assert html |> Floki.find(".pagination-link") |> length() == 8

assert Floki.find(html, "a[aria-label='Go to page 1']")
assert Floki.find(html, "a[aria-label='Go to page 20']")
assert Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.find(html, "li a[aria-label='Go to page 20']")

for i <- 10..15 do
assert Floki.find(html, ".a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand All @@ -965,11 +965,11 @@ defmodule Flop.PhoenixTest do
assert html |> Floki.find(".pagination-ellipsis") |> length() == 2
assert html |> Floki.find(".pagination-link") |> length() == 7

assert Floki.find(html, "a[aria-label='Go to page 1']")
assert Floki.find(html, "a[aria-label='Go to page 20']")
assert Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.find(html, "li a[aria-label='Go to page 20']")

for i <- 9..13 do
assert Floki.find(html, "a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand All @@ -987,11 +987,11 @@ defmodule Flop.PhoenixTest do
assert html |> Floki.find(".pagination-ellipsis") |> length() == 2
assert html |> Floki.find(".pagination-link") |> length() == 7

assert Floki.find(html, "a[aria-label='Go to page 1']")
assert Floki.find(html, "a[aria-label='Go to page 20']")
assert Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.find(html, "li a[aria-label='Go to page 20']")

for i <- 8..12 do
assert Floki.find(html, "a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand All @@ -1009,11 +1009,11 @@ defmodule Flop.PhoenixTest do
assert html |> Floki.find(".pagination-ellipsis") |> length() == 2
assert html |> Floki.find(".pagination-link") |> length() == 7

assert Floki.find(html, "a[aria-label='Go to page 1']")
assert Floki.find(html, "a[aria-label='Go to page 20']")
assert Floki.find(html, "li a[aria-label='Go to page 1']")
assert Floki.find(html, "li a[aria-label='Go to page 20']")

for i <- 9..13 do
assert Floki.find(html, "a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand All @@ -1031,10 +1031,10 @@ defmodule Flop.PhoenixTest do
assert html |> Floki.find(".pagination-ellipsis") |> length() == 1
assert html |> Floki.find(".pagination-link") |> length() == 6

assert Floki.find(html, "a[aria-label='Go to page 20']")
assert Floki.find(html, "li a[aria-label='Go to page 20']")

for i <- 1..5 do
assert Floki.find(html, "a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand All @@ -1052,10 +1052,10 @@ defmodule Flop.PhoenixTest do
assert html |> Floki.find(".pagination-ellipsis") |> length() == 1
assert html |> Floki.find(".pagination-link") |> length() == 6

assert Floki.find(html, "a[aria-label='Go to page 1']")
assert Floki.find(html, "li a[aria-label='Go to page 1']")

for i <- 16..20 do
assert Floki.find(html, "a[aria-label='Go to page #{i}']")
assert Floki.find(html, "li a[aria-label='Go to page #{i}']")
end
end

Expand Down

0 comments on commit 7da3392

Please sign in to comment.