@@ -54,6 +54,7 @@ $.widget( "ui.selectmenu", {
54
54
this . _bind ( this . button , this . _buttonEvents ) ;
55
55
56
56
this . _drawMenu ( ) ;
57
+ this . refresh ( ) ;
57
58
58
59
if ( this . options . disabled ) {
59
60
this . disable ( ) ;
@@ -74,15 +75,18 @@ $.widget( "ui.selectmenu", {
74
75
css : {
75
76
width : this . element . outerWidth ( )
76
77
} ,
78
+ 'aria-expanded' : false ,
79
+ 'aria-autocomplete' : 'list' ,
77
80
'aria-owns' : this . ids . menu ,
78
81
'aria-haspopup' : true
79
82
} )
80
83
. button ( {
81
- label : this . element . find ( "option:selected" ) . text ( ) ,
82
84
icons : {
83
85
primary : ( this . options . dropdown ? 'ui-icon-triangle-1-s' : 'ui-icon-triangle-2-n-s' )
84
86
}
85
- } ) ;
87
+ } )
88
+ // change ARIA role
89
+ . attr ( 'role' , 'combobox' ) ;
86
90
87
91
// wrap and insert new button
88
92
this . buttonWrap = $ ( '<span />' )
@@ -122,7 +126,9 @@ $.widget( "ui.selectmenu", {
122
126
var item = ui . item . data ( "item.selectmenu" ) ,
123
127
oldIndex = that . element [ 0 ] . selectedIndex ;
124
128
125
- that . _setIndex ( item . index ) ;
129
+ // change native select element
130
+ that . element [ 0 ] . selectedIndex = item . index ;
131
+ that . _setSelected ( ) ;
126
132
that . _trigger ( "select" , event , { item : item } ) ;
127
133
128
134
if ( item . index != oldIndex ) {
@@ -145,7 +151,7 @@ $.widget( "ui.selectmenu", {
145
151
}
146
152
} )
147
153
// change ARIA role
148
- . attr ( 'role' , 'menubox ' ) ;
154
+ . attr ( 'role' , 'listbox ' ) ;
149
155
150
156
// change menu styles?
151
157
this . _setOption ( "dropdown" , this . options . dropdown ) ;
@@ -165,38 +171,27 @@ $.widget( "ui.selectmenu", {
165
171
166
172
this . _readOptions ( ) ;
167
173
this . _renderMenu ( this . menu , this . items ) ;
168
-
174
+
169
175
this . menu . menu ( "refresh" ) ;
170
- // button option label wont work here
171
- this . button . children ( '.ui-button-text' ) . text ( this . items [ this . element [ 0 ] . selectedIndex ] . label ) ;
172
176
173
177
// adjust ARIA
174
- this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) . find ( 'a' ) . attr ( 'role' , 'option' ) ;
175
- this . menu . attr ( "aria-activedescendant" , this . menu . find ( "li.ui-menu-item a" ) . eq ( this . element [ 0 ] . selectedIndex ) . attr ( "id" ) ) ;
178
+ this . _getItems ( ) . find ( 'a' ) . attr ( 'role' , 'option' ) ;
179
+ this . _setSelected ( ) ;
176
180
177
181
// set and transfer disabled state
178
182
this . _getCreateOptions ( ) ;
179
- if ( this . options . disabled ) {
180
- this . disable ( ) ;
181
- } else {
182
- this . enable ( )
183
- }
183
+ this . _setOption ( "disabled" , this . options . disabled ) ;
184
184
} ,
185
185
186
186
open : function ( event ) {
187
187
if ( ! this . options . disabled ) {
188
- // init menu when initial opened
189
- if ( ! this . wasOpen ) {
190
- this . refresh ( ) ;
191
- this . wasOpen = true ;
192
- }
193
-
194
188
var currentItem = this . _getSelectedItem ( ) ;
195
189
196
190
this . _toggleButtonStyle ( ) ;
197
191
198
192
this . menuWrap . addClass ( 'ui-selectmenu-open' ) ;
199
193
this . menu . attr ( "aria-hidden" , false ) ;
194
+ this . button . attr ( "aria-expanded" , true ) ;
200
195
// needs to be fired after the document click event has closed all other Selectmenus
201
196
// otherwise the current item is not indicated
202
197
// TODO check if this should be handled by Menu
@@ -236,7 +231,8 @@ $.widget( "ui.selectmenu", {
236
231
this . _toggleButtonStyle ( ) ;
237
232
238
233
this . menuWrap . removeClass ( 'ui-selectmenu-open' ) ;
239
- this . menu . attr ( "aria-hidden" , true ) ;
234
+ this . menu . attr ( "aria-hidden" , true ) ;
235
+ this . button . attr ( "aria-expanded" , false ) ;
240
236
this . isOpen = false ;
241
237
242
238
if ( focus ) {
@@ -282,14 +278,9 @@ $.widget( "ui.selectmenu", {
282
278
} ,
283
279
284
280
_move : function ( direction , event ) {
285
- // init menu when not done yet
286
- if ( ! this . wasOpen ) {
287
- this . refresh ( ) ;
288
- this . wasOpen = true ;
289
- }
290
281
if ( direction == "first" || direction == "last" ) {
291
282
// set focus manually for first or last item
292
- this . menu . menu ( "focus" , event , this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) [ direction ] ( ) ) ;
283
+ this . menu . menu ( "focus" , event , this . _getItems ( ) [ direction ] ( ) ) ;
293
284
} else {
294
285
// if menu is closed we need to focus the element first to indicate correct element
295
286
if ( ! this . isOpen ) {
@@ -306,7 +297,11 @@ $.widget( "ui.selectmenu", {
306
297
} ,
307
298
308
299
_getSelectedItem : function ( ) {
309
- return this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) . eq ( this . element [ 0 ] . selectedIndex ) ;
300
+ return this . _getItems ( ) . eq ( this . element [ 0 ] . selectedIndex ) ;
301
+ } ,
302
+
303
+ _getItems : function ( ) {
304
+ return this . menu . find ( "li" ) . not ( '.ui-selectmenu-optgroup' ) ;
310
305
} ,
311
306
312
307
_toggle : function ( event ) {
@@ -360,6 +355,7 @@ $.widget( "ui.selectmenu", {
360
355
break ;
361
356
case $ . ui . keyCode . HOME :
362
357
case $ . ui . keyCode . PAGE_UP :
358
+ console . log ( "test" ) ;
363
359
this . _move ( "first" , event ) ;
364
360
break ;
365
361
case $ . ui . keyCode . END :
@@ -376,9 +372,14 @@ $.widget( "ui.selectmenu", {
376
372
}
377
373
} ,
378
374
379
- _setIndex : function ( index ) {
380
- this . element [ 0 ] . selectedIndex = index ;
381
- this . button . button ( "option" , "label" , this . items [ index ] . label ) ;
375
+ _setSelected : function ( ) {
376
+ var item = this . _getSelectedItem ( ) . find ( "a" ) ;
377
+ // update button text
378
+ this . button . button ( "option" , "label" , item . text ( ) ) ;
379
+ // change ARIA attr
380
+ this . button . add ( this . menu ) . attr ( "aria-activedescendant" , item . attr ( "id" ) ) ;
381
+ this . _getItems ( ) . find ( "a" ) . attr ( "aria-selected" , false ) ;
382
+ item . attr ( "aria-selected" , true ) ;
382
383
} ,
383
384
384
385
_setOption : function ( key , value ) {
0 commit comments