Skip to content

Commit 20d19db

Browse files
Selectmenu: ARIA tweaks for keyboard events and closed menu operation
1 parent c59fbba commit 20d19db

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

ui/jquery.ui.selectmenu.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ $.widget( "ui.selectmenu", {
7373

7474
_drawButton: function() {
7575
var tabindex = this.element.attr( 'tabindex' );
76+
var labelSelector = "label[for='" + this.element.attr("id") + "']";
77+
78+
// Find existing label
79+
this.labelElement = $( labelSelector ).uniqueId();
7680

7781
// hide original select tag
7882
this.element.hide();
@@ -85,6 +89,7 @@ $.widget( "ui.selectmenu", {
8589
id: this.ids.button,
8690
width: this.element.outerWidth(),
8791
role: 'combobox',
92+
'aria-labelledby': this.labelElement.attr("id"),
8893
'aria-expanded': false,
8994
'aria-autocomplete': 'list',
9095
'aria-owns': this.ids.menu,
@@ -150,6 +155,10 @@ $.widget( "ui.selectmenu", {
150155
}
151156
}
152157
that.focus = item.index;
158+
159+
// Set ARIA active decendent
160+
that.button.attr( "aria-activedescendant", item.element.uniqueId().attr( "id" ) );
161+
153162
},
154163
// set ARIA role
155164
role: 'listbox'
@@ -330,6 +339,9 @@ $.widget( "ui.selectmenu", {
330339
this._move( "next", event );
331340
}
332341
break;
342+
case $.ui.keyCode.SPACE:
343+
this._toggle( event );
344+
break;
333345
case $.ui.keyCode.LEFT:
334346
this._move( "previous", event );
335347
break;
@@ -372,6 +384,7 @@ $.widget( "ui.selectmenu", {
372384
// change ARIA attr
373385
this.menuItems.find( "a" ).attr( "aria-selected", false );
374386
this._getSelectedItem().find( "a" ).attr( "aria-selected", true );
387+
this.button.attr( "aria-activedescendant", item.element.uniqueId().attr( "id" ) );
375388
},
376389

377390
_setOption: function( key, value ) {
@@ -427,6 +440,7 @@ $.widget( "ui.selectmenu", {
427440
this.menuWrap.remove();
428441
this.buttonWrap.remove();
429442
this.element.show();
443+
this.labelElement.removeUniqueId();
430444
}
431445
});
432446

0 commit comments

Comments
 (0)