Repository: woylie/flop_phoenix
Pull request #462 (2025-05-03 16:37:36)

set pagination list attributes via attribute
contributes to #411 


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b433c4e..9586a1f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,9 @@
 
 - Set page link aria label function with `page_link_aria_label_fun` attribute
   on `Flop.Phoenix.pagination/1` component instead of using `opts`.
+- Set pagination list attributes with `list_attrs` attribute instead of
+  `pagination_list_attrs` option.
+- Remove default class for pagination list.
 - Use `<button>` elements for pagination if no `path` is set.
 - Add `rel` attribute to previous/next links.
 - Mark up disabled previous/next links of the pagination as
@@ -131,6 +134,20 @@ Remove the `:pagination_link_aria_label` option and set the
   >
 ```
 
+Remove the `:pagination_list_attrs` option and set the `list_attrs` attribute
+instead. If you relied on the default class, set it explicitly.
+
+```diff
+  <Flop.Phoenix.pagination
+    meta={@meta}
+    path={@path}
+    opts={[
+-     pagination_list_attrs: [class: "pagination-list"]
+    ]}
++     list_attrs={[class: "pagination-list"]}
+  >
+```
+
 ## [0.24.0] - 2025-02-01
 
 ### Added
diff --git a/config/config.exs b/config/config.exs
index 7fb9f77..83687e3 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -3,5 +3,4 @@ import Config
 config :phoenix, :json_library, Jason
 
 config :flop_phoenix,
-  pagination: [opts: {MyAppWeb.CoreComponents, :pagination_opts}],
   table: [opts: {MyAppWeb.CoreComponents, :table_opts}]
diff --git a/lib/flop_phoenix.ex b/lib/flop_phoenix.ex
index 5852e3b..1b0b532 100644
--- a/lib/flop_phoenix.ex
+++ b/lib/flop_phoenix.ex
@@ -28,6 +28,7 @@ defmodule Flop.Phoenix do
     def pagination(assigns) do
       ~H\"""
       <Flop.Phoenix.pagination
+        class="pagination"
         meta={@meta}
         path={@path}
         on_paginate={@on_paginate}
@@ -141,14 +142,11 @@ defmodule Flop.Phoenix do
 
   - `:pagination_link_attrs` - The attributes for the pagination links.
     Default: `#{inspect(Pagination.default_opts()[:pagination_link_attrs])}`.
-  - `:pagination_list_attrs` - The attributes for the pagination list.
-    Default: `#{inspect(Pagination.default_opts()[:pagination_list_attrs])}`.
   - `:pagination_list_item_attrs` - The attributes for the pagination list items.
     Default: `#{inspect(Pagination.default_opts()[:pagination_list_item_attrs])}`.
   """
   @type pagination_option ::
           {:pagination_link_attrs, keyword}
-          | {:pagination_list_attrs, keyword}
           | {:pagination_list_item_attrs, keyword}
 
   @typedoc """
@@ -364,6 +362,12 @@ defmodule Flop.Phoenix do
     described in the `Customization` section of the module documentation.
     """
 
+  attr :list_attrs, :list,
+    default: [],
+    doc: """
+    Attributes to be added to the `<ul>` that contains the page links.
+    """
+
   attr :rest, :global,
     default: %{"aria-label": "Pagination"},
     doc: """
@@ -496,6 +500,7 @@ defmodule Flop.Phoenix do
           page_range_start={p.page_range_start}
           target={@target}
           total_pages={p.total_pages}
+          {@list_attrs}
         />
         <.pagination_link
           :if={p.pagination_type in [:first, :last]}
@@ -538,10 +543,11 @@ defmodule Flop.Phoenix do
   attr :target, :string, required: true
   attr :total_pages, :integer, required: true
   attr :ellipsis, :any
+  attr :rest, :global
 
   defp page_links(assigns) do
     ~H"""
-    <ul {@opts[:pagination_list_attrs]}>
+    <ul {@rest}>
       <li :if={@page_range_start > 1} {@opts[:pagination_list_item_attrs]}>
         <.pagination_link
           target={@target}
diff --git a/lib/flop_phoenix/pagination.ex b/lib/flop_phoenix/pagination.ex
index c4a4358..60bf5cd 100644
--- a/lib/flop_phoenix/pagination.ex
+++ b/lib/flop_phoenix/pagination.ex
@@ -269,7 +269,6 @@ defmodule Flop.Phoenix.Pagination do
   def default_opts do
     [
       pagination_link_attrs: [class: "pagination-link"],
-      pagination_list_attrs: [class: "pagination-list"],
       pagination_list_item_attrs: []
     ]
   end


Test patch:
diff --git a/test/flop_phoenix_test.exs b/test/flop_phoenix_test.exs
index ec5b0be..822015a 100644
--- a/test/flop_phoenix_test.exs
+++ b/test/flop_phoenix_test.exs
@@ -492,7 +492,7 @@ defmodule Flop.PhoenixTest do
         <Flop.Phoenix.pagination meta={@meta} path="/pets" />
         """)
 
-      assert find_one(html, "ul[class='pagination-links']")
+      assert find_one(html, "ul")
 
       assert link = find_one(html, "li a[aria-label='Go to page 1']")
       assert attribute(link, "class") == "pagination-link"
@@ -585,7 +585,7 @@ defmodule Flop.PhoenixTest do
         <Flop.Phoenix.pagination
           meta={@meta}
           path="/pets"
-          opts={[pagination_list_attrs: [class: "p-list", title: "boop"]]}
+          list_attrs={[class: "p-list", title: "boop"]}
         />
         """)
 
diff --git a/test/support/my_app_web/components/core_components.ex b/test/support/my_app_web/components/core_components.ex
index 55e1c02..92891ce 100644
--- a/test/support/my_app_web/components/core_components.ex
+++ b/test/support/my_app_web/components/core_components.ex
@@ -87,10 +87,6 @@ defmodule MyAppWeb.CoreComponents do
     """
   end
 
-  def pagination_opts do
-    [pagination_list_attrs: [class: "pagination-links"]]
-  end
-
   def table_opts do
     [table_attrs: [class: "sortable-table"]]
   end