Problem/Motivation

We can't create a custom pagination structure because we must follow the convention:

<ul class="js-pager__items">
    <li><a class="pagination__item" href="#" aria-current="page" aria-label="Current Page, Page 1">1</a></li>
    <li><a class="pagination__item" href="#" aria-label="Page 2">2</a></li>
    <li><a class="pagination__item" href="#" aria-label="Page 3">3</a></li>
    <li><a class="pagination__item" href="#" aria-label="Page 4">4</a></li>
    <li><a class="pagination__item" href="#" aria-label="Page 5">5</a></li>
  </ul>

It means that we must have `ul.js-pager__items > li > a` toajax pagination work correctly.
But in li tag, we can use a lot of different tags like:

<a>, <abbr>, <address>, <article>, <aside>, <audio>, <b>,<bdo>, <bdi>, <blockquote>, <br>, <button>, <canvas>, <cite>, <code>, <command>, <data>, <datalist>, <del>, <details>, <dfn>, <div>, <dl>, <em>, <embed>, <fieldset>, <figure>, <footer>, <form>, <h1>, <h2>, <h3>, <h4>, <h5>, <h6>, <header>, <hgroup>, <hr>, <i>, <iframe>, <img>, <input>, <ins>, <kbd>, <keygen>, <label>, <main>, <map>, <mark>, <math>, <menu>, <meter>, <nav>, <noscript>, <object>, <ol>, <output>, <p>, <picture>, <pre>, <progress>, <q>, <ruby>, <s>, <samp>, <script>, <section>, <select>, <small>, <span>, <strong>, <sub>, <sup>, <svg>, <table>, <template>, <textarea>, <time>, <ul>, <var>, <video>, <wbr>

and Text.
When we build pagination using a different structure than what I showed above it will not work.

Steps to reproduce

Create ajax pagination like on example below:

<ul class="js-pager__items">
    <li><div><a class="pagination__item" href="#" aria-current="page" aria-label="Current Page, Page 1">1</a></div></li>
    <li><div><a class="pagination__item" href="#" aria-label="Page 2">2</a></div></li>
    <li><div><a class="pagination__item" href="#" aria-label="Page 3">3</a></div></li>
    <li><div><a class="pagination__item" href="#" aria-label="Page 4">4</a></div></li>
    <li><div><a class="pagination__item" href="#" aria-label="Page 5">5</a></div></li>
  </ul>

Pagination is not working as expected (ajax is not applied to that pagination).

Proposed resolution

We should add one more selector `.js-pager__items a` that will give us a possibility to create custom pagination without any issues.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#20 3195543-15.patch1.43 KBpatrikk
#14 3195543-14.patch557 bytesameymudras

Issue fork drupal-3195543

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Adam Szalapski created an issue. See original summary.

szalapski.adam@gmail.com’s picture

Status: Active » Needs review
lendude’s picture

Category: Bug report » Feature request
Status: Needs review » Needs work

Sounds more like a feature request, nothing is broken per se.

The new selector completely overlaps with the existing selector, ul.js-pager__items > li > a, .js-pager__items a,, so all instances captured by the first selector are also captured by the second selector. So wouldn't it make more sense to just replace the existing selector with the new one?

szalapski.adam@gmail.com’s picture

The code is updated, please review now.

szalapski.adam@gmail.com’s picture

Status: Needs work » Needs review

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

florianmuellerch’s picture

Ran into the same issue. I'm using bootstrap theme, but I wanted to theme this load more button myself. I didn't want to use ul and li's because Bootstrap puts styles on top of regular theme styles which are not overridable (despite with !important which is disgusting).

So I added the patch from your merge request and it works just fine, I can now have my pager in my own desired markup which is perfect. I'd love to see this change being commited to core! Thanks for your investigative effort!

florianmuellerch’s picture

Status: Needs review » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work

We have test coverage that this JS works in \Drupal\Tests\views\FunctionalJavascript\PaginationAJAXTest which is good.

We need a new MR or patch for 10.x because JS standards have changed there and we no longer have .es6 files on these branches.

Going to ping @lauriii and @nod_ just to make sure the selector changes are okay. I think being a little less specific here is a good idea.

ameymudras’s picture

Version: 9.5.x-dev » 10.1.x-dev
StatusFileSize
new557 bytes
ameymudras’s picture

Status: Needs work » Needs review
nod_’s picture

Status: Needs review » Reviewed & tested by the community

Had a look at contrib, doesn't seem to be used/overridden much or at all.

Like lauriii said in slack only problem would be if a view is nested somehow but thankfully there is code to prevent initializing pager in a nested view.

Changing the selector makes sense for flexibility

  • lauriii committed 1389e1ee on 10.1.x
    Issue #3195543 by Adam Szalapski, ameymudras, florianmuellerCH, alexpott...
lauriii’s picture

Status: Reviewed & tested by the community » Fixed

Committed 1389e1e and pushed to 10.1.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

patrikk’s picture

StatusFileSize
new1.43 KB

I've created patch for 9.5, with same fix as for 10.1