Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
[custom select] Make keyboard navigation work for multiple choice sel…
Browse files Browse the repository at this point in the history
…ect -- Fixes: #4039
  • Loading branch information
Gabriel Schulhof committed Jun 20, 2012
1 parent 84eb4c9 commit 26bd1ef
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions js/jquery.mobile.forms.select.custom.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,13 @@ define( [
self.select.trigger( "change" );
}

//hide custom select for single selects only
if ( !self.isMultiple ) {
// hide custom select for single selects only - otherwise focus clicked item
// We need to grab the clicked item the hard way, because the list may have been rebuilt
if ( self.isMultiple ) {
self.list.find( "li:not(.ui-li-divider)" ).eq( newIndex )
.addClass( "ui-btn-down-" + widget.options.theme ).find( "a" ).first().focus();
}
else {
self.close();
}

Expand Down Expand Up @@ -351,7 +356,11 @@ define( [
}, 300);

function focusMenuItem() {
self.list.find( "." + $.mobile.activeBtnClass + " a" ).focus();
var selector = self.list.find( "." + $.mobile.activeBtnClass + " a" );
if ( selector.length === 0 ) {
selector = self.list.find( "li.ui-btn:not(:jqmData(placeholder='true')) a" );
}
selector.first().focus();
}

if ( menuHeight > screenHeight - 80 || !$.support.scrollTop ) {
Expand Down Expand Up @@ -453,9 +462,10 @@ define( [
dataIconAttr = dataPrefix + 'icon',
dataRoleAttr = dataPrefix + 'role',
fragment = document.createDocumentFragment(),
isPlaceholderItem = false,
optGroup;

for (var i = 0; i < numOptions;i++){
for (var i = 0; i < numOptions;i++, isPlaceholderItem = false){
var option = $options[i],
$option = $(option),
parent = option.parentNode,
Expand All @@ -482,6 +492,7 @@ define( [

if (needPlaceholder && (!option.getAttribute( "value" ) || text.length == 0 || $option.jqmData( "placeholder" ))) {
needPlaceholder = false;
isPlaceholderItem = true;
if ( o.hidePlaceholderMenuItems ) {
classes.push( "ui-selectmenu-placeholder" );
}
Expand All @@ -497,6 +508,9 @@ define( [
}
item.setAttribute(dataIndexAttr,i);
item.setAttribute(dataIconAttr,dataIcon);
if ( isPlaceholderItem ) {
item.setAttribute( dataPrefix + "placeholder", true );
}
item.className = classes.join(" ");
item.setAttribute('role','option');
anchor.setAttribute('tabindex','-1');
Expand Down

0 comments on commit 26bd1ef

Please sign in to comment.