12
12
* jquery.ui.widget.js
13
13
*/
14
14
( function ( $ ) {
15
+
16
+ var idIncrement = 0 ;
15
17
16
18
$ . widget ( "ui.menu" , {
17
19
_create : function ( ) {
18
20
var self = this ;
21
+ this . menuId = this . element . attr ( "id" ) || "ui-menu-" + idIncrement ++ ;
19
22
this . element
20
23
. addClass ( "ui-menu ui-widget ui-widget-content ui-corner-all" )
21
24
. attr ( {
22
- role : "listbox" ,
23
- "aria-activedescendant" : "ui-active-menuitem "
25
+ id : this . menuId ,
26
+ role : "listbox "
24
27
} )
25
28
. bind ( "click.menu" , function ( event ) {
26
29
if ( self . options . disabled ) {
@@ -120,6 +123,7 @@ $.widget("ui.menu", {
120
123
} ,
121
124
122
125
activate : function ( event , item ) {
126
+ var self = this ;
123
127
this . deactivate ( ) ;
124
128
if ( this . _hasScroll ( ) ) {
125
129
var borderTop = parseFloat ( $ . curCSS ( this . element [ 0 ] , "borderTopWidth" , true ) ) || 0 ,
@@ -137,17 +141,26 @@ $.widget("ui.menu", {
137
141
this . active = item . first ( )
138
142
. children ( "a" )
139
143
. addClass ( "ui-state-hover" )
140
- . attr ( "id" , "ui-active-menuitem" )
144
+ . attr ( "id" , function ( index , id ) {
145
+ return ( self . itemId = id || self . menuId + "-activedescendant" ) ;
146
+ } )
141
147
. end ( ) ;
148
+ // need to remove the attribute before adding it for the screenreader to pick up the change
149
+ // see http://groups.google.com/group/jquery-a11y/msg/929e0c1e8c5efc8f
150
+ this . element . removeAttr ( "aria-activedescenant" ) . attr ( "aria-activedescenant" , self . itemId ) ;
142
151
this . _trigger ( "focus" , event , { item : item } ) ;
143
152
} ,
144
153
145
154
deactivate : function ( event ) {
146
- if ( ! this . active ) { return ; }
155
+ if ( ! this . active ) {
156
+ return ;
157
+ }
147
158
148
- this . active . children ( "a" )
149
- . removeClass ( "ui-state-hover" )
150
- . removeAttr ( "id" ) ;
159
+ var self = this ;
160
+ this . active . children ( "a" ) . removeClass ( "ui-state-hover" ) ;
161
+ // remove only generated id
162
+ $ ( "#" + self . menuId + "-activedescendant" ) . removeAttr ( "id" ) ;
163
+ this . element . removeAttr ( "aria-activedescenant" ) ;
151
164
this . _trigger ( "blur" , event ) ;
152
165
this . active = null ;
153
166
} ,
0 commit comments