@@ -42,14 +42,6 @@ $.widget( "ui.selectmenu", {
42
42
// array of button and menu id's
43
43
this . ids = { id : selectmenuId , button : selectmenuId + '-button' , menu : selectmenuId + '-menu' } ;
44
44
45
- // catch click event of the label
46
- this . _on ( {
47
- 'click' : function ( event ) {
48
- this . button . focus ( ) ;
49
- event . preventDefault ( ) ;
50
- }
51
- } ) ;
52
-
53
45
this . _drawButton ( ) ;
54
46
this . _on ( this . button , this . _buttonEvents ) ;
55
47
this . _hoverable ( this . button ) ;
@@ -74,8 +66,15 @@ $.widget( "ui.selectmenu", {
74
66
_drawButton : function ( ) {
75
67
var tabindex = this . element . attr ( 'tabindex' ) ;
76
68
77
- // Find existing label
78
- this . labelElement = $ ( "label[for='" + this . ids . id + "']" ) . uniqueId ( ) ;
69
+ // fix existing label
70
+ this . label = $ ( "label[for='" + this . ids . id + "']" ) . attr ( "for" , this . ids . button ) ;
71
+ // catch click event of the label
72
+ this . _on ( this . label , {
73
+ 'click' : function ( event ) {
74
+ this . button . focus ( ) ;
75
+ event . preventDefault ( ) ;
76
+ }
77
+ } ) ;
79
78
80
79
// hide original select tag
81
80
this . element . hide ( ) ;
@@ -88,7 +87,6 @@ $.widget( "ui.selectmenu", {
88
87
id : this . ids . button ,
89
88
width : this . element . outerWidth ( ) ,
90
89
role : 'combobox' ,
91
- 'aria-labelledby' : this . labelElement . attr ( "id" ) ,
92
90
'aria-expanded' : false ,
93
91
'aria-autocomplete' : 'list' ,
94
92
'aria-owns' : this . ids . menu ,
@@ -378,12 +376,16 @@ $.widget( "ui.selectmenu", {
378
376
} ,
379
377
380
378
_setSelected : function ( item ) {
379
+ var itemId = this . menuItems . eq ( item . index ) . find ( "a" ) . attr ( "id" ) ;
381
380
// update button text
382
381
this . buttonText . html ( item . label ) ;
383
382
// change ARIA attr
384
383
this . menuItems . find ( "a" ) . attr ( "aria-selected" , false ) ;
385
384
this . _getSelectedItem ( ) . find ( "a" ) . attr ( "aria-selected" , true ) ;
386
- this . button . attr ( "aria-activedescendant" , this . menuItems . eq ( item . index ) . find ( "a" ) . attr ( "id" ) ) ;
385
+ this . button . attr ( {
386
+ "aria-activedescendant" : itemId ,
387
+ "aria-labelledby" : itemId
388
+ } ) ;
387
389
} ,
388
390
389
391
_setOption : function ( key , value ) {
@@ -440,7 +442,7 @@ $.widget( "ui.selectmenu", {
440
442
this . buttonWrap . remove ( ) ;
441
443
this . element . show ( ) ;
442
444
this . element . removeUniqueId ( ) ;
443
- this . labelElement . removeUniqueId ( ) ;
445
+ this . label . attr ( "for" , this . ids . id ) ;
444
446
}
445
447
} ) ;
446
448
0 commit comments