ITADN

Bug: Can't add HTML class with series_nav

#864OpenJasonBarnabe 创建于 2026-01-22
bug
J
JasonBarnabecommented
### 👀 Before submitting... - [x] I upgraded to pagy version 43.2.7 - [x] I asked [Pagy AI](https://gurubase.io/g/pagy) (Good starting point for further investigation). - [x] I searched through the [Documentation](https://ddnexus.github.io/pagy/), [Issues](https://github.com/ddnexus/pagy/issues), and [Q&A](https://github.com/ddnexus/pagy/discussions/categories/q-a) ### 🧐 REQUIREMENTS - [x] I am providing a VALID code file that confirms the bug - [x] I am NOT posting any of the USELESS THINGS listed above - [x] I am aware that this issue will be automatically closed if the code file is missing or INVALID ### 💬 Description https://ddnexus.github.io/pagy/toolbox/helpers/#common-nav-options says I can use the `id` and `aria_label` options to set those attributes in the HTML. Why not allow also setting HTML `class` (and more generally, any HTML attribute)? Pagy AI says I can, but the class does not appear in the HTML. ``` # frozen_string_literal: true # DESCRIPTION # Reproduce generic/simple issues # # DOC # https://ddnexus.github.io/pagy/playground/#repro-app # # BIN HELP # pagy -h # # DEV USAGE # pagy clone repro # pagy ./repro.ru # # URL # http://127.0.0.1:8000 VERSION = '43.2.7' if VERSION != Pagy::VERSION Warning.warn("\n>>> WARNING! '#{File.basename(__FILE__)}-#{VERSION}' running with 'pagy-#{Pagy::VERSION}'! <<< \n\n") end run_from_repo = Pagy::ROOT.join('pagy.gemspec').exist? # Bundle require 'bundler/inline' gemfile(!run_from_repo) do source 'https://rubygems.org' gem 'oj' gem 'puma' gem 'sinatra' end # Edit this section adding the legacy as needed # Pagy initializer Pagy.options[:client_max_limit] = 100 # Sinatra setup require 'sinatra/base' # Sinatra application class PagyRepro < Sinatra::Base include Pagy::Method get('/javascripts/:file') do format = params[:file].split('.').last if format == 'js' content_type 'application/javascript' elsif format == 'map' content_type 'application/json' end send_file Pagy::ROOT.join('javascripts', params[:file]) end # Edit this action as needed get '/' do collection = MockCollection.new @pagy, @records = pagy(collection) # simplest form # @pagy, @records = pagy(:offset, collection, limit: 7, client_max_limit: 30) # @pagy, @records = pagy(:countish, collection, ttl: 20) # @pagy, @records = pagy(:countless, collection) # @pagy, @records = pagy(Array(1..1000)) # response.headers.merge!(@pagy.headers_hash) erb :main end # Views template :layout do <<~ERB <!DOCTYPE html> <html lang="en"> <head> <title>Pagy Repro App</title> <script src="javascripts/pagy.js"></script> <script> window.addEventListener("load", Pagy.init); </script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style type="text/css"> @media screen { html, body { font-size: 1rem; line-height: 1.2; padding: 0; margin: 0; } } body { background: white !important; margin: 0 !important; font-family: sans-serif !important; } .main-content { padding: 1rem 1.5rem 2rem !important; } .pagy, .pagy-bootstrap, .pagy-bulma { padding: .5em; margin: .3em 0; width: fit-content; box-shadow: 5px 5px 10px 0px rgba(0,0,0,0.2); } /* Quick demo for overriding the element style attribute of certain pagy helpers .pagy input[style] { width: 5rem !important; } */ /* If you want to customize the style, please replace the line below with the actual file content */ <%= Pagy::ROOT.join('stylesheets/pagy.css').read %> </style> </head> <body> <%= yield %> </body> </html> ERB end template :main do <<~ERB <div class="main-content"> <h1>Pagy Repro App</h1> <p> Self-contained, standalone app usable to easily reproduce any pagy issue.</p> <h2>Versions</h2> <ul> <li>Ruby: <%= RUBY_VERSION %></li> <li>Rack: <%= Rack::RELEASE %></li> <li>Sinatra: <%= Sinatra::VERSION %></li> <li>Pagy: <%= Pagy::VERSION %></li> </ul> <h3>Collection</h3> <p id="records">@records: <%= @records.join(',') %></p> <hr> <h4>@pagy.series_nav</h4> <%= @pagy.series_nav(id: 'series-nav', aria_label: 'Pages nav', class: 'my-custom-class') %> <h4>@pagy.series_nav_js (responsive)</h4> <%= @pagy.series_nav_js(id: 'series-nav-js-responsive', aria_label: 'Pages nav_js_responsive', steps: { 0 => 5, 500 => 7, 600 => 9, 700 => 11 }) %> <h4>@pagy.input_nav_js</h4> <%= @pagy.input_nav_js(id: 'input-nav-js', aria_label: 'Pages input_nav_js') %> <h4>@pagy.limit_tag_js</h4> <%= @pagy.limit_tag_js(id: 'limit-tag-js') %> <h4>@pagy.info_tag</h4> <%= @pagy.info_tag(id: 'pagy-info') %> </div> ERB end end # Simple array-based collection that acts as a standard DB collection. # Use it as a simple way to get a collection that acts as an AR scope, but without any DB # or create an ActiveRecord class or anything else that you need instead class MockCollection < Array def initialize(arr = Array(1..1000)) super @collection = clone end def offset(value) @collection = self[value..] || [] self end def limit(value) @collection.empty? ? [] : @collection[0, value] end def count(*) size end end run PagyRepro ```
0 条评论