Are you a GenerateCustomer?

Do you have an active GP Premium or GenerateBlocks Pro license key?

Create a GenerateSupport account for GeneratePress and GenerateBlocks support in one dedicated place.

Create an account
Already have a GenerateSupport account? Login

Just browsing?

Feel free to browse the forums. Support for our free versions is provided on WordPress.org (GeneratePress, GenerateBlocks).

Want to become a premium user? Learn more below.

How to set Loop Items & Page Numbers to tabindex -1

  • Good morning,

    I am currently creating an internal post navigation with the query loop and would like to exclude it from the tabindex order. Unfortunately, the links in the loop items and the page numbers do not respond when I give them the HTML attribute tabindex=“-1”. (for accessibility-reason)

    I am working with GP Pro and GB and GB Pro Version 2.0.0-beta.3

    Do you have any ideas on how I can implement this?

    Many thanks, Stephan

  • Hi there,

    can you add the tabindex attribute so I can see the issue ?

  • Hi David, it’s active now

  • Just to be clear , are these the ones :

    https://app.screencast.com/hYKFXj2QaEs2g

    As they are working for me.
    Let me know

  • These the ones and the loop-items, yes.

    To explain, I want to exclude them from tabbing. Here I still can tab through all links, including these ones.
    For example the fixed contact-button on the right side: this is exluded from tabbing, here the tabindex=”-1″ is working fine.

  • Ah ok.
    It would need some Javascript to do that:

    
    const container = document.querySelector('.gb-query-loop-pagination');
    container.querySelectorAll('a').forEach(element => {
      element.setAttribute('tabindex', '-1');
    });
    
  • It doesn’t work, sorry 🙁

  • How did you add the code?

    For example:

    1. in Appearance > Elements -> Add New –> Hook
    2. set the Hook to wp_footer
    3. set the Display Rules location to the page you want to apply it to.
    4. in the hook editor add the Javascript in <script> tags eg.

    
    <script>
    const container = document.querySelector('.gb-query-loop-pagination');
    container.querySelectorAll('a').forEach(element => {
      element.setAttribute('tabindex', '-1');
    });
    </script>
    
  • omg, I forgot to set it into the script-tags, thank you David.

    It works perfectly as always, is it possible to realize it for the loop-item links above too?

  • Yes, you can include .gb-loop-item in your code.

    so change the code to:

    // Select both the pagination container and loop items
    const containers = document.querySelectorAll('.gb-query-loop-pagination, .gb-loop-item');
    
    containers.forEach(container => {
      container.querySelectorAll('a').forEach(element => {
        element.setAttribute('tabindex', '-1');
      });
    });
    
  • Perfect Ying, this works!

    What would I do without your continuous and highest professional support, thanks again, Ying and David.

  • You are welcome   🙂

  • Hi, on a similar note we often have to add tabindex=”-1″ to focusable elements that are ARIA hidden, to comply with WCAG 2.1 (A), WCAG 2.0 (A), WCAG 2.2 (A).

    Is there a version of the script above that can apply tabindex=”-1″ to anchor <a> elements if a parent element has aria-hidden=”true” AND a specific class, (eg class=”ariahidden” )?

    Many thanks

    Ben

  • This is not in our support forum scope as it’s not related to our products.

    But it’s similar to the original solution, so here it is:

    document.querySelectorAll('.ariahidden[aria-hidden="true"]').forEach(function(parent) {
        parent.querySelectorAll('a').forEach(function(anchor) {
            anchor.setAttribute('tabindex', '-1');
        });
    });
  • many thanks, appreciated.
    Ben

  • No Problem 🙂

Viewing 16 posts - 1 through 16 (of 16 total)
  • You must be logged in to reply to this topic.