Skip to content

Commit ecc0d0e

Browse files
committed
Menu: Implemented new (experimental) ARIA based on discussions on the jquery-a11y list.
1 parent 9949fa4 commit ecc0d0e

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

ui/jquery.ui.menu.js

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
* jquery.ui.widget.js
1313
*/
1414
(function($) {
15+
16+
var idIncrement = 0;
1517

1618
$.widget("ui.menu", {
1719
_create: function() {
1820
var self = this;
21+
this.menuId = this.element.attr( "id" ) || "ui-menu-" + idIncrement++;
1922
this.element
2023
.addClass( "ui-menu ui-widget ui-widget-content ui-corner-all" )
2124
.attr({
22-
role: "listbox",
23-
"aria-activedescendant": "ui-active-menuitem"
25+
id: this.menuId,
26+
role: "listbox"
2427
})
2528
.bind( "click.menu", function( event ) {
2629
if ( self.options.disabled ) {
@@ -120,6 +123,7 @@ $.widget("ui.menu", {
120123
},
121124

122125
activate: function( event, item ) {
126+
var self = this;
123127
this.deactivate();
124128
if ( this._hasScroll() ) {
125129
var borderTop = parseFloat( $.curCSS( this.element[0], "borderTopWidth", true) ) || 0,
@@ -137,17 +141,26 @@ $.widget("ui.menu", {
137141
this.active = item.first()
138142
.children( "a" )
139143
.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+
})
141147
.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);
142151
this._trigger( "focus", event, { item: item } );
143152
},
144153

145154
deactivate: function(event) {
146-
if (!this.active) { return; }
155+
if (!this.active) {
156+
return;
157+
}
147158

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" );
151164
this._trigger( "blur", event );
152165
this.active = null;
153166
},

0 commit comments

Comments
 (0)