Projet

Général

Profil

0001-accessibility-replace-focus-at-the-beginning-of-list.patch

A. Berriot, 29 août 2022 09:59

Télécharger (2,03 ko)

Voir les différences:

Subject: [PATCH] accessibility: replace focus at the beginning of list on
 pagination change (#41128)

 combo/public/static/js/combo.public.js | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
combo/public/static/js/combo.public.js
363 363
    var paginate_by = parseInt($pagination.data('paginate-by'));
364 364
    // Get all <li> inside the same div as us, ignoring whether they are part of
365 365
    // different <ul>
366
    var wrapper = $pagination.parent();
367
    wrapper.attr('tabindex', -1)
366 368
    var items = $pagination.parent().find('li');
367 369
    var max_page_index = Math.ceil(items.length / paginate_by);
368 370
    if (items.length <= paginate_by) {
369 371
      return;
370 372
    }
371 373

  
372
    function update_page(step) {
374
    function update_page(step, focus_first_item) {
373 375
      page_index = page_index + step;
374 376
      if (page_index == 0) {
375 377
        $pagination.find('.cell-items-pagination-prev').prop('disabled', true);
......
384 386
      start_item = paginate_by * page_index;
385 387
      items.hide();
386 388
      items.slice(start_item, start_item + paginate_by).show();
389
      if (focus_first_item) {
390
        wrapper.focus()
391
      }
387 392
    };
388 393

  
389
    $pagination.find('.cell-items-pagination-prev').click(function() { update_page(-1); });
390
    $pagination.find('.cell-items-pagination-next').click(function() { update_page(1); });
391
    update_page(0);
394
    $pagination.find('.cell-items-pagination-prev').click(function() { update_page(-1, true); });
395
    $pagination.find('.cell-items-pagination-next').click(function() { update_page(1, true); });
396
    update_page(0, false);
392 397
    $pagination.prop('hidden', null);
393 398
  });
394 399
  $('.cell-items-pagination').each(function(idx, elem) {
395
-