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
| Comment | File | Size | Author |
|---|---|---|---|
| #20 | 3195543-15.patch | 1.43 KB | patrikk |
| #14 | 3195543-14.patch | 557 bytes | ameymudras |
Issue fork drupal-3195543
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
Comment #3
szalapski.adam@gmail.com commentedComment #4
lendudeSounds 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?Comment #5
szalapski.adam@gmail.com commentedThe code is updated, please review now.
Comment #6
szalapski.adam@gmail.com commentedComment #11
florianmuellerchRan 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!
Comment #12
florianmuellerchComment #13
alexpottWe 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.
Comment #14
ameymudras commentedComment #15
ameymudras commentedComment #16
nod_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
Comment #18
lauriiiCommitted 1389e1e and pushed to 10.1.x. Thanks!
Comment #20
patrikk commentedI've created patch for 9.5, with same fix as for 10.1