@@ -30,7 +30,7 @@ define([
30
30
minSearchLength : 2 ,
31
31
responseFieldElements : 'ul li' ,
32
32
selectClass : 'selected' ,
33
- template : '<li class="{{row_class}}" title="{{title }}"> {{title}}<span class="amount">{{num_of_results}}</span></li>' ,
33
+ template : '<li class="{{row_class}}" id="qs-option-{{index }}" role="option"><span class="qs-option-name"> {{title}}</ span><span aria-hidden="true" class="amount">{{num_of_results}}</span></li>' ,
34
34
submitBtn : 'button[type="submit"]' ,
35
35
searchLabel : '[data-role=minisearch-label]'
36
36
} ,
@@ -55,6 +55,7 @@ define([
55
55
this . searchLabel . removeClass ( 'active' ) ;
56
56
}
57
57
this . autoComplete . hide ( ) ;
58
+ this . _updateAriaHasPopup ( false ) ;
58
59
} , this ) , 250 ) ;
59
60
} , this ) ) ;
60
61
@@ -66,7 +67,10 @@ define([
66
67
this . element . on ( 'keydown' , this . _onKeyDown ) ;
67
68
this . element . on ( 'input propertychange' , this . _onPropertyChange ) ;
68
69
69
- this . searchForm . on ( 'submit' , this . _onSubmit ) ;
70
+ this . searchForm . on ( 'submit' , $ . proxy ( function ( ) {
71
+ this . _onSubmit ( ) ;
72
+ this . _updateAriaHasPopup ( false ) ;
73
+ } , this ) ) ;
70
74
} ,
71
75
/**
72
76
* @private
@@ -84,6 +88,18 @@ define([
84
88
return this . responseList . indexList ? this . responseList . indexList . last ( ) : false ;
85
89
} ,
86
90
91
+ /**
92
+ * @private
93
+ * @param {Boolean } show Set attribute aria-haspopup to "true/false" for element.
94
+ */
95
+ _updateAriaHasPopup : function ( show ) {
96
+ if ( show ) {
97
+ this . element . attr ( 'aria-haspopup' , 'true' ) ;
98
+ } else {
99
+ this . element . attr ( 'aria-haspopup' , 'false' ) ;
100
+ }
101
+ } ,
102
+
87
103
/**
88
104
* Clears the item selected from the suggestion list and resets the suggestion list.
89
105
* @private
@@ -108,9 +124,9 @@ define([
108
124
if ( isEmpty ( value ) ) {
109
125
e . preventDefault ( ) ;
110
126
}
111
-
127
+
112
128
if ( this . responseList . selected ) {
113
- this . element . val ( this . responseList . selected . attr ( 'title' ) ) ;
129
+ this . element . val ( this . responseList . selected . find ( '.qs-option-name' ) . text ( ) ) ;
114
130
}
115
131
} ,
116
132
@@ -153,6 +169,8 @@ define([
153
169
this . _getFirstVisibleElement ( ) . addClass ( this . options . selectClass ) ;
154
170
this . responseList . selected = this . _getFirstVisibleElement ( ) ;
155
171
}
172
+ this . element . val ( this . responseList . selected . find ( '.qs-option-name' ) . text ( ) ) ;
173
+ this . element . attr ( 'aria-activedescendant' , this . responseList . selected . attr ( 'id' ) ) ;
156
174
}
157
175
break ;
158
176
case $ . ui . keyCode . UP :
@@ -165,6 +183,8 @@ define([
165
183
this . _getLastElement ( ) . addClass ( this . options . selectClass ) ;
166
184
this . responseList . selected = this . _getLastElement ( ) ;
167
185
}
186
+ this . element . val ( this . responseList . selected . find ( '.qs-option-name' ) . text ( ) ) ;
187
+ this . element . attr ( 'aria-activedescendant' , this . responseList . selected . attr ( 'id' ) ) ;
168
188
}
169
189
break ;
170
190
default :
@@ -189,14 +209,15 @@ define([
189
209
} ,
190
210
source = this . options . template ,
191
211
template = Handlebars . compile ( source ) ,
192
- dropdown = $ ( '<ul></ul>' ) ,
212
+ dropdown = $ ( '<ul role="listbox" ></ul>' ) ,
193
213
value = this . element . val ( ) ;
194
214
195
215
this . submitBtn . disabled = isEmpty ( value ) ;
196
216
197
217
if ( value . length >= parseInt ( this . options . minSearchLength , 10 ) ) {
198
218
$ . get ( this . options . url , { q : value } , $ . proxy ( function ( data ) {
199
- $ . each ( data , function ( index , element ) {
219
+ $ . each ( data , function ( index , element ) {
220
+ element . index = index ;
200
221
var html = template ( element ) ;
201
222
dropdown . append ( html ) ;
202
223
} ) ;
@@ -206,7 +227,14 @@ define([
206
227
. find ( this . options . responseFieldElements + ':visible' ) ;
207
228
208
229
this . _resetResponseList ( false ) ;
209
-
230
+ this . element . removeAttr ( 'aria-activedescendant' ) ;
231
+
232
+ if ( this . responseList . indexList . length ) {
233
+ this . _updateAriaHasPopup ( true ) ;
234
+ } else {
235
+ this . _updateAriaHasPopup ( false ) ;
236
+ }
237
+
210
238
this . responseList . indexList
211
239
. on ( 'click' , function ( e ) {
212
240
this . responseList . selected = $ ( e . target ) ;
@@ -216,6 +244,7 @@ define([
216
244
this . responseList . indexList . removeClass ( this . options . selectClass ) ;
217
245
$ ( e . target ) . addClass ( this . options . selectClass ) ;
218
246
this . responseList . selected = $ ( e . target ) ;
247
+ this . element . attr ( 'aria-activedescendant' , $ ( e . target ) . attr ( 'id' ) ) ;
219
248
} . bind ( this ) )
220
249
. on ( 'mouseout' , function ( e ) {
221
250
if ( ! this . _getLastElement ( ) && this . _getLastElement ( ) . hasClass ( this . options . selectClass ) ) {
@@ -227,6 +256,8 @@ define([
227
256
} else {
228
257
this . _resetResponseList ( true ) ;
229
258
this . autoComplete . hide ( ) ;
259
+ this . _updateAriaHasPopup ( false ) ;
260
+ this . element . removeAttr ( 'aria-activedescendant' ) ;
230
261
}
231
262
}
232
263
} ) ;
0 commit comments