diff --git a/app/javascript/loading_spinner.js b/app/javascript/loading_spinner.js index 98186dc4..2626047e 100644 --- a/app/javascript/loading_spinner.js +++ b/app/javascript/loading_spinner.js @@ -22,6 +22,10 @@ document.addEventListener('turbo:frame-render', function(event) { if (firstResult) { firstResult.focus(); } + + // Remove the spinner now that things are ready + document.getElementById('search-results').classList.remove('spinner'); + // Clear the pending action window.pendingFocusAction = null; }; @@ -53,7 +57,12 @@ document.addEventListener('click', function(event) { // Handle pagination clicks if (clickedElement.closest('.pagination-container') || clickedElement.matches('.first a, .previous a, .next a')) { + // Throw the spinner on the search results immediately + document.getElementById('search-results').classList.add('spinner'); + + // Position the window at the top of the results window.scrollTo({ top: 0, behavior: 'smooth' }); + window.pendingFocusAction = 'pagination'; }