diff --git a/hdbt.libraries.yml b/hdbt.libraries.yml index 47f438858..0381cf299 100644 --- a/hdbt.libraries.yml +++ b/hdbt.libraries.yml @@ -191,3 +191,8 @@ news-archive: dependencies: - core/drupalSettings - core/drupal + +search-helper: + version: 1.x + js: + src/js/search-helper.js: {} diff --git a/hdbt.theme b/hdbt.theme index e09eeb54d..a871d09b3 100644 --- a/hdbt.theme +++ b/hdbt.theme @@ -1687,3 +1687,10 @@ function hdbt_theme_suggestions_container_alter(array &$suggestions, array &$var array_unshift($suggestions, 'container__' . $type . '__' . $name); } + +/** + * Implements hook_preprocess_HOOK(). + */ +function hdbt_preprocess_views_exposed_form(array &$variables) { + $variables['#attached']['library'][] = 'hdbt/search-helper'; +} diff --git a/src/js/search-helper.js b/src/js/search-helper.js new file mode 100644 index 000000000..c7fb0da32 --- /dev/null +++ b/src/js/search-helper.js @@ -0,0 +1,15 @@ +(function ($) { + + // Set focus on search result count + $(document).ajaxComplete(function onDataLoaded(e, xhr, settings) { + // Check form ID to prevent mixing on multi-form page + const viewDomId = settings.extraData.view_dom_id; + const resultsContainerEl = $(`[data-id-number=${ viewDomId }]`); + const resultCountEl = $('[class$="__count-container"]', resultsContainerEl[0])[0]; + + if (!resultCountEl) return; + resultCountEl.setAttribute('tabindex', '-1'); + resultCountEl.focus(); + resultCountEl.scrollIntoView({behavior: 'smooth', block: 'center'}); + }); +})(jQuery); diff --git a/templates/views/views-view--service-list--block-search.html.twig b/templates/views/views-view--service-list--block-search.html.twig index 9a2ca9cb4..a4141fb22 100644 --- a/templates/views/views-view--service-list--block-search.html.twig +++ b/templates/views/views-view--service-list--block-search.html.twig @@ -50,19 +50,22 @@ {% endif %} - {% if is_ajax_request or total_rows > pager_items_per_page %} - {{ exposed }} + {{ exposed }} +
- {{ total_rows ?? 0 }} - {% trans with {'context': 'Service list count'}%}service{% plural total_rows %}services{% endtrans %} - - {% endif %} + {% if total_rows %} + {{ total_rows }} + {% trans with {'context': 'Service list count'}%}service{% plural total_rows %}services{% endtrans %} + {% endif %} + {{ empty }} + +
{{ attachment_before }} {{ rows }} - {{ empty }} + {{ pager }} {{ attachment_after }} diff --git a/templates/views/views-view--unit-search.html.twig b/templates/views/views-view--unit-search.html.twig index d45b0e302..a40d2256e 100644 --- a/templates/views/views-view--unit-search.html.twig +++ b/templates/views/views-view--unit-search.html.twig @@ -54,17 +54,18 @@ {{ exposed }} {{ attachment_before }} -
- {% if total_rows %} +
- {{ total_rows }} - {% trans with {'context': 'Unit search count'}%}result{% plural total_rows %}results{% endtrans %} + {% if total_rows %} + {{ total_rows }} + {% trans with {'context': 'Unit search count'}%}result{% plural total_rows %}results{% endtrans %} + {% endif %} + + {{ empty }} - {% endif %} {{ rows }} - {{ empty }} {{ pager }}
{{ attachment_after }} diff --git a/templates/views/views-view-unformatted--service-list--block-search.html.twig b/templates/views/views-view-unformatted--service-list--block-search.html.twig index e679cd671..1b1c8b85f 100644 --- a/templates/views/views-view-unformatted--service-list--block-search.html.twig +++ b/templates/views/views-view-unformatted--service-list--block-search.html.twig @@ -16,10 +16,8 @@ */ #} -
{% for row in rows %}
{{- row.content -}}
{% endfor %} -