Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation - pagination improvements #9102

Open
lb- opened this issue Aug 31, 2022 · 16 comments
Open

Documentation - pagination improvements #9102

lb- opened this issue Aug 31, 2022 · 16 comments

Comments

@lb-
Copy link
Member

lb- commented Aug 31, 2022

Is your proposal related to a problem?

This is a good first issue for someone wanting to work with JavaScript and the documentation code.

Describe the solution you'd like

Additional context

@lb-
Copy link
Member Author

lb- commented Aug 31, 2022

Note - this was flagged as part of the UX Unification (GSoC 2022) project - but de-scoped.

Labelling as a good first issue though.

@akshay-gupta7
Copy link

Hi @lb- , can you assign this to me

@lb-
Copy link
Member Author

lb- commented Sep 13, 2022

@akshay-gupta7 we do not really assign issues to contributors, only the core team in some cases.

Feel free to get started with this and prepare a PR when you are ready.

Reach out if you need a hand, and remember there is a #new-contributors channel on Slack.

@akshay-gupta7
Copy link

@lb- sure, thank you. I'll get started with this.

@akshay-gupta7
Copy link

Hi @lb- , raised a PR against this issue. Please do have a look whenever you can

@akshay-gupta7
Copy link

Hi @lb- , thank you for taking out the time to review my code. As per your review, I have put in the suggestions. Please do have a look whenever you can.

@lb-
Copy link
Member Author

lb- commented Oct 6, 2022

I have put some feedback on the PR but just adding some solution ideas here, but the general gist is that we probably should tackle this in two parts.

A. clean up the existing code (use proper event listeners, move the code to an external file search.js and solve any large linting issues.
B. Adopt a new behaviour/set of buttons for the pagination.

For item B, we need to rethink the JS solution which iterates through the 'pages' and adds buttons for each page, instead it can be much simpler and just have TWO buttons (prev/next) and one status label (Page X of Y) and avoid lots of the need for aria-current.

Here is a rough potential base HTML for the template, leveraging data attributes to attach our JS to and places to attach the X/Y labels to. Note: This may need a full review in a screen reader and accessibility checker also.

{% extends "layout.html" %}
{% set title = _('Search') %}

{% block body %}
    <noscript>
        <div id="fallback" class="admonition warning">
            <p class="last">
                {% trans trimmed %}
                    Please activate JavaScript to enable the search functionality.
                {% endtrans %}
            </p>
        </div>
    </noscript>

    <div id="search-results">
    </div>

    <nav class="pagination" aria-label="Pagination" hidden="true" data-pagination="7">
        <button type="button" class="pagination-button pagination-previous" data-pagination-previous aria-describedby="pagination-status">
            {% trans trimmed %}← Previous{% endtrans %}
        </button>
        <span id="pagination-status">
            {% trans trimmed %}Page <span data-pagination-status-x></span> of <span data-pagination-status-y></span>{% endtrans %}
        </span>
        <button type="button" class="pagination-button pagination-next" data-pagination-next aria-describedby="pagination-status">
            {% trans trimmed %}Next →{% endtrans %}
        </button>
    </nav>
{% endblock %}

Then in the JS, we can make things much simpler, and just attach to these elements. Something like the below as a start.

function displayPagination(page, totalPages) {
  const pagination = document.querySelector('[data-pagination]');
  const maxPagesToDisplay = Number(pagination.dataset.pagination) || 7;

  // Hide previous/next button if showing first/last page
  const previousButton = pagination.querySelector('[data-pagination-previous]');
  previousButton.hidden = page === 0;

  const nextButton = pagination.querySelector('[data-pagination-next]');
  nextButton.hidden = page === totalPages - 1;
  
  // update status labels
  const xLabel = pagination.querySelector('[data-pagination-status-x]');
  xLabel.innerText = `${page}`;

  const yLabel = pagination.querySelector('[data-pagination-status-y]');
  yLabel.innerText = `${Math.min(totalPages, maxPagesToDisplay)}`;

 // add event listeners here to the prev/next button

This approach avoids a lot of the JS writing of content (Page X of Y) and keeps that in the initial DOM, and hopefully we can avoid the complexity of iteration.

This may not cover the full solution but just some ideas on approaches.

Also, we need to consider the following when adopting this new code.

  • Browser support, esp. Safari ~14+ & mobile devices
  • Dark mode support (does everything look good in dark mode and non-dark mode)
  • JS does not have errors or console warnings at all, including pages that do not use the search results
  • Code is commented where possible and JSDOC is used to help document this as it is a bit complex
  • Event listeners are removed when needed - or at least the code, if run, will not do anything odd when pages change
  • All buttons have type="button" so they do not cause a page reload https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button
  • All aria-current attributes are removed IF we deem they are no longer required for the new approach https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-current
  • All aria attributes make sense, and where possible, we use semantic DOM elements instead (e.g. we may not need the aria-label on the outer container if we just used a proper header element for that nav element).

All of this means that the change of the button layout is probably a larger task on its own so any PRs are welcome that make partial progress towards this overall goal.

Any feedback is welcome on this rough code also.

cc @akshay-gupta7

@aym-n
Copy link
Contributor

aym-n commented Jan 18, 2023

@lb- can you assign me this issue? i would like to work on it

@lb-
Copy link
Member Author

lb- commented Jan 21, 2023

@aym-n there is a PR already started #9224 and also some direction above. Please review it all and if you want to give this a go as a new PR - go for it.

@akshay-gupta7 - it's been a few months so I'm assuming you are ok for someone else to give this a go. Let me know otherwise.

@aym-n
Copy link
Contributor

aym-n commented Jan 22, 2023

  • clean up the existing code (use proper event listeners, move the code to an external file search.js and solve any large linting issues.
  • we need to rethink the JS solution

@aym-n
Copy link
Contributor

aym-n commented Jan 22, 2023

working on cleaning up the code and the tasks mentioned in the #9224

aym-n added a commit to aym-n/wagtail that referenced this issue Jan 22, 2023
commit 224b03e
Author: Ayman Makroo <ajm8982@gmail.com>
Date:   Sun Jan 22 14:25:50 2023 +0530

    Updated QuerySelector

    Updated Query Selectors to use Data attributes instead of Class or Id names

    Also Removed Id tags for buttons

commit 2fb6ce0
Author: Akshay Gupta <gravity.akshay@gmail.com>
Date:   Sat Sep 24 18:13:37 2022 +0530

    Remove extra dynamic elements for pagination buttons

commit 9fb8a90
Author: Akshay Gupta <gravity.akshay@gmail.com>
Date:   Fri Sep 23 17:27:37 2022 +0530

    Prettier formatting

commit 26f0cf5
Author: Akshay Gupta <gravity.akshay@gmail.com>
Date:   Thu Sep 22 00:31:33 2022 +0530

    Move comments above function and add window.docsearch to resolve lint error

commit 9618750
Author: Akshay Gupta <gravity.akshay@gmail.com>
Date:   Wed Sep 21 23:55:48 2022 +0530

    Merge layout and search.js into one JS file to resolve undefined lint errors

commit c40fa6a
Author: Akshay Gupta <gravity.akshay@gmail.com>
Date:   Tue Sep 20 18:20:40 2022 +0530

    Add layout.html JS code to separate layout.js and refactored to remove lint errors

commit 3892b0a
Author: Akshay Gupta <gravity.akshay@gmail.com>
Date:   Sun Sep 18 21:07:33 2022 +0530

    Implement pagination updates in response to wagtail#9102

commit 522d382
Author: Akshay Gupta <gravity.akshay@gmail.com>
Date:   Sat Sep 17 18:55:30 2022 +0530

    Implement pagination improvements(# 9102)
@ArijeetBanerjee

This comment was marked as duplicate.

@lb-
Copy link
Member Author

lb- commented Jan 23, 2023

@aym-n just a tip - when you are referencing an issue you just need the hash in front of it, not the PR.

Observe that PR#9224 does not make a link but #9224 does.

See https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/autolinked-references-and-urls

@aym-n
Copy link
Contributor

aym-n commented Jan 24, 2023

Observe that PR#9224 does not make a link but #9224 does.

Thank You!
Will keep that in mind from now on :)

@MashiatK
Copy link

MashiatK commented Feb 8, 2023

I want to work on this. If the issue is open, please assign it to me.

@gasman
Copy link
Collaborator

gasman commented Feb 8, 2023

@MashiatK Please read the discussion above - there is already a pull request for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants