1+ // Loading spinner behavior for search results
2+ document . 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+ }
24+ }
25+ // Clear the pending action
26+ window . pendingFocusAction = null ;
27+ }
28+ } ) ;
29+
30+ document . addEventListener ( 'click' , function ( event ) {
31+ const clickedElement = event . target ;
32+
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)
43+ if ( clickedElement . closest ( '.pagination-container' ) ||
44+ clickedElement . matches ( '.first a, .previous a, .next a' ) ) {
45+ const tabs = document . querySelector ( '.tab-navigation' ) ;
46+ if ( tabs ) {
47+ tabs . classList . add ( 'loading' ) ;
48+ }
49+ window . scrollTo ( { top : 0 , behavior : 'smooth' } ) ;
50+ window . pendingFocusAction = 'pagination' ;
51+ }
52+ } ) ;
0 commit comments