Skip to content

Commit 9504d33

Browse files
committed
changed typeahead attribute to data-typeahead. added trigger and focus for LI element as well as A element in order to properly select and highlight them. added missing css attribute into css.
1 parent cf6eff7 commit 9504d33

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

themes/base/jquery.ui.selectmenu.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
----------------------------------*/
33
.ui-selectmenu { display: block; display: inline-block; position: relative; height: 2.2em; vertical-align: middle; text-decoration: none; overflow: hidden; zoom: 1; }
44
.ui-selectmenu-icon { position:absolute; right:6px; margin-top:-8px; top: 50%; }
5+
.ui-selectmenu-item-focus {}
56
.ui-selectmenu-menu { padding:0; margin:0; position:absolute; top: 0; display: none; z-index: 1005;} /* z-index: 1005 to make selectmenu work with dialog */
67
.ui-selectmenu-menu ul { padding:0; margin:0; list-style:none; position: relative; overflow: auto; overflow-y: auto ; overflow-x: hidden; }
78
.ui-selectmenu-open { display: block; }

ui/jquery.ui.selectmenu.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ $.widget("ui.selectmenu", {
100100
.bind('click.selectmenu', function() {
101101
return false;
102102
})
103+
// key events for closed menu
103104
.bind("keydown.selectmenu", function(event) {
104105
var ret = false;
105106
switch (event.keyCode) {
@@ -208,6 +209,7 @@ $.widget("ui.selectmenu", {
208209

209210
// transfer menu click to menu button
210211
this.list
212+
// key events for open menu
211213
.bind("keydown.selectmenu", function(event) {
212214
var ret = false;
213215
switch (event.keyCode) {
@@ -287,7 +289,7 @@ $.widget("ui.selectmenu", {
287289
selected: opt.attr('selected'),
288290
disabled: opt.attr('disabled'),
289291
classes: opt.attr('class'),
290-
typeahead: opt.attr('typeahead'),
292+
typeahead: opt.attr('data-typeahead'),
291293
parentOptGroup: opt.parent('optgroup'),
292294
bgImage: o.bgImage.call(opt)
293295
});
@@ -317,7 +319,7 @@ $.widget("ui.selectmenu", {
317319
thisAAttr[ 'aria-disabled' ] = selectOptionData[ i ].disabled;
318320
}
319321
if ( selectOptionData[ i ].typeahead ) {
320-
thisAAttr[ 'typeahead' ] = selectOptionData[ i ].typeahead;
322+
thisAAttr[ 'data-typeahead' ] = selectOptionData[ i ].typeahead;
321323
}
322324
var thisA = $('<a/>', thisAAttr);
323325
var thisLi = $('<li/>', thisLiAttr)
@@ -492,7 +494,6 @@ $.widget("ui.selectmenu", {
492494
if ( self._typeAhead_chars.length < 2 ||
493495
(self._typeAhead_chars.substr(-2, 1) === c && self._typeAhead_cycling) ) {
494496
self._typeAhead_cycling = true;
495-
496497
// Match only the first character and loop
497498
matchee = c;
498499
}
@@ -514,8 +515,8 @@ $.widget("ui.selectmenu", {
514515
this._focusedOptionLi().data('index')) || 0;
515516

516517
for (var i = 0; i < this._optionLis.length; i++) {
517-
var thisText = this._optionLis.eq(i).text().substr(0, matchee.length).toLowerCase();
518-
518+
// use the typeahead text if we have it
519+
var thisText = (this._optionLis.eq(i).find("a").attr('data-typeahead') || this._optionLis.eq(i).find("a").text()).substr(0, matchee.length).toLowerCase();
519520
if ( thisText === matchee ) {
520521
if ( self._typeAhead_cycling ) {
521522
if ( nextIndex === null )
@@ -532,11 +533,9 @@ $.widget("ui.selectmenu", {
532533
}
533534

534535
if ( nextIndex !== null ) {
535-
// Why using trigger() instead of a direct method to select the
536-
// index? Because we don't what is the exact action to do, it
537-
// depends if the user is typing on the element or on the popped
538-
// up menu
539-
this._optionLis.eq(nextIndex).find("a").trigger( eventType );
536+
// trigger both the li and the a to properly enabling styling?
537+
// seems like we need to pick one of these things instead
538+
this._optionLis.eq(nextIndex).trigger( eventType ).find("a").trigger( eventType );
540539
}
541540

542541
self._typeAhead_timer = window.setTimeout(function() {
@@ -688,6 +687,7 @@ $.widget("ui.selectmenu", {
688687
var newIndex = parseInt(this._optionLis.filter(amt).data('index'), 10);
689688
}
690689

690+
691691
if (newIndex < 0) {
692692
newIndex = 0;
693693
}
@@ -707,7 +707,9 @@ $.widget("ui.selectmenu", {
707707
(amt > 0) ? ++amt : --amt;
708708
this._moveFocus(amt, newIndex);
709709
} else {
710-
this._optionLis.eq(newIndex).find('a:eq(0)').attr('id',activeID).focus();
710+
this._focusedOptionLi().removeClass(this.widgetBaseClass + '-item-focus ui-state-hover');
711+
this._optionLis.eq(newIndex).addClass(this.widgetBaseClass + '-item-focus ui-state-hover')
712+
.find('a:eq(0)').attr('id',activeID).focus();
711713
}
712714

713715
this.list.attr('aria-activedescendant', activeID);
@@ -877,4 +879,4 @@ $.widget("ui.selectmenu", {
877879
}
878880
});
879881

880-
})(jQuery);
882+
})(jQuery);

0 commit comments

Comments
 (0)