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