@@ -48,6 +48,8 @@ class Pagination {
4848 window . in2studyfinder . getInstance ( instanceId ) . filter . call ( targetPage ) ;
4949 } else {
5050 LoaderUtility . enableLoader ( ) ;
51+ // Announce loading to screen readers
52+ this . announceToScreenReader ( 'loading' ) ;
5153
5254 fetch ( url , {
5355 method : 'POST' ,
@@ -63,10 +65,71 @@ class Pagination {
6365
6466 LoaderUtility . disableLoader ( ) ;
6567 window . in2studyfinder . getInstance ( instanceId ) . update ( this . studyfinderElement ) ;
68+
69+ // Announce results update to screen readers
70+ this . announceResultsUpdate ( ) ;
6671 } ) ;
6772 }
6873 } ;
6974
75+ /**
76+ * Announce loading or result changes to screen readers via aria-live region
77+ *
78+ * @param {string } messageType - Type of message: 'loading' or 'resultsUpdated'
79+ */
80+ announceToScreenReader ( messageType ) {
81+ const feedbackElement = this . studyfinderElement . querySelector ( '#filter-feedback' ) ;
82+ if ( ! feedbackElement ) return ;
83+
84+ let message = '' ;
85+ const dataAttr = `data-${ messageType . replace ( / ( [ A - Z ] ) / g, '-$1' ) . toLowerCase ( ) } -text` ;
86+ message = feedbackElement . getAttribute ( dataAttr ) || '' ;
87+
88+ // Clear first to ensure change detection
89+ feedbackElement . textContent = '' ;
90+
91+ // Use setTimeout to ensure the clear is processed before setting new text
92+ setTimeout ( ( ) => {
93+ feedbackElement . textContent = message ;
94+ } , 100 ) ;
95+ }
96+
97+ /**
98+ * Announce results update with current page info to screen readers
99+ */
100+ announceResultsUpdate ( ) {
101+ const feedbackElement = this . studyfinderElement . querySelector ( '#filter-feedback' ) ;
102+ if ( ! feedbackElement ) return ;
103+
104+ // Get the count from the updated DOM
105+ const itemCountElement = this . studyfinderElement . querySelector ( '.in2studyfinder__item-count p' ) ;
106+
107+ if ( itemCountElement ) {
108+ const countText = itemCountElement . textContent . trim ( ) ;
109+ const countMatch = countText . match ( / ^ \d + / ) ;
110+
111+ if ( countMatch ) {
112+ const count = parseInt ( countMatch [ 0 ] , 10 ) ;
113+ let message = '' ;
114+
115+ if ( count === 1 ) {
116+ message = feedbackElement . getAttribute ( 'data-results-count-single' ) || '' ;
117+ } else {
118+ const template = feedbackElement . getAttribute ( 'data-results-count-multiple' ) || '' ;
119+ message = template . replace ( '%s' , count ) ;
120+ }
121+
122+ // Clear first to ensure change detection
123+ feedbackElement . textContent = '' ;
124+
125+ // Use setTimeout to ensure the clear is processed before setting new text
126+ setTimeout ( ( ) => {
127+ feedbackElement . textContent = message ;
128+ } , 100 ) ;
129+ }
130+ }
131+ }
132+
70133 onClick ( ) {
71134 }
72135}
0 commit comments