1- // Loading spinner behavior for search results
1+ // Loading spinner behavior for pagination (Turbo Frame updates)
22document . addEventListener ( 'turbo:frame-render' , function ( event ) {
3- // Remove loading state from tabs when frame finishes loading
4- const tabs = document . querySelector ( '.tab-navigation' ) ;
5- if ( tabs ) {
6- tabs . classList . remove ( 'loading' ) ;
7- }
8-
9- // Focus management after content loads
10- if ( window . pendingFocusAction ) {
11- if ( window . pendingFocusAction === 'pagination' ) {
12- // Focus on first result for pagination
13- const firstResult = document . querySelector ( '.results-list .result h3 a, .results-list .result .record-title a' ) ;
14- if ( firstResult ) {
15- firstResult . focus ( ) ;
16- }
17- } else if ( window . pendingFocusAction === 'tab-switch' ) {
18- // Focus on results summary for tab switches
19- const resultsContext = document . querySelector ( '.results-context' ) ;
20- if ( resultsContext ) {
21- resultsContext . setAttribute ( 'tabindex' , '-1' ) ;
22- resultsContext . focus ( ) ;
23- }
3+ if ( window . pendingFocusAction === 'pagination' ) {
4+ // Focus on first result for pagination
5+ const firstResult = document . querySelector ( '.results-list .result h3 a, .results-list .result .record-title a' ) ;
6+ if ( firstResult ) {
7+ firstResult . focus ( ) ;
248 }
259 // Clear the pending action
2610 window . pendingFocusAction = null ;
@@ -30,22 +14,9 @@ document.addEventListener('turbo:frame-render', function(event) {
3014document . addEventListener ( 'click' , function ( event ) {
3115 const clickedElement = event . target ;
3216
33- // Handle pagination clicks (scroll to top and set pending focus action)
34- if ( clickedElement . matches ( '.tab-link' ) ) {
35- const tabs = document . querySelector ( '.tab-navigation' ) ;
36- if ( tabs ) {
37- tabs . classList . add ( 'loading' ) ;
38- }
39- window . pendingFocusAction = 'tab-switch' ;
40- }
41-
42- // Handle pagination clicks (scroll to top and set pending focus action)
17+ // Handle pagination clicks
4318 if ( clickedElement . closest ( '.pagination-container' ) ||
4419 clickedElement . matches ( '.first a, .previous a, .next a' ) ) {
45- const tabs = document . querySelector ( '.tab-navigation' ) ;
46- if ( tabs ) {
47- tabs . classList . add ( 'loading' ) ;
48- }
4920 window . scrollTo ( { top : 0 , behavior : 'smooth' } ) ;
5021 window . pendingFocusAction = 'pagination' ;
5122 }
0 commit comments