Skip to content
Permalink
Browse files

Selectmenu: improve disabled item handling

  • Loading branch information
fnagel committed Oct 29, 2013
1 parent 480e89b commit f3e4b24485a34c89ee4032605d853c1b3e0a4e7e
Showing with 26 additions and 13 deletions.
  1. +1 −1 tests/visual/selectmenu/selectmenu.html
  2. +25 −12 ui/jquery.ui.selectmenu.js
@@ -156,7 +156,7 @@ <h2>Disabled tests</h2>

<label for="disabled2">Disabled options</label>
<select name="disabled2" id="disabled2">
<option value="1">1</option>
<option value="1" disabled="disabled">1</option>
<option value="2" selected="selected">2</option>
<option value="3">3</option>
<option disabled="disabled" value="4">4</option>
@@ -287,17 +287,24 @@ $.widget( "ui.selectmenu", {
},

_move: function( direction, event ) {
var filter = ".ui-menu-item",
item, next;

if ( this.isOpen ) {
item = this.menuItems.eq( this.focusIndex );
} else {
item = this.menuItems.eq( this.element[ 0 ].selectedIndex );
filter += ":not(.ui-state-disabled)";
}

if ( direction === "first" || direction === "last" ) {
// Set focus manually for first or last item
this.menu.menu( "focus", event, this.menuItems[ direction ]() );
next = item[ direction === "first" ? "prevAll" : "nextAll" ]( filter ).eq( -1 );
} else {
if ( direction === "previous" && this.menu.menu( "isFirstItem" ) ||
direction === "next" && this.menu.menu( "isLastItem" ) ) {
return;
}
next = item[ direction + "All" ]( filter ).eq( 0 );
}

// Move to and focus next or prev item
this.menu.menu( direction, event );
if ( next.length ) {
this.menu.menu( "focus", event, next );
}
},

@@ -340,14 +347,14 @@ $.widget( "ui.selectmenu", {
break;
case $.ui.keyCode.ENTER:
if ( this.isOpen ) {
this.menuInstance.select( event );
this._selectMenu( event );
}
break;
case $.ui.keyCode.UP:
if ( event.altKey ) {
this._toggle( event );
} else {
this._move( "previous", event );
this._move( "prev", event );
}
break;
case $.ui.keyCode.DOWN:
@@ -359,13 +366,13 @@ $.widget( "ui.selectmenu", {
break;
case $.ui.keyCode.SPACE:
if ( this.isOpen ) {
this.menuInstance.select( event );
this._selectMenu( event );
} else {
this._toggle( event );
}
break;
case $.ui.keyCode.LEFT:
this._move( "previous", event );
this._move( "prev", event );
break;
case $.ui.keyCode.RIGHT:
this._move( "next", event );
@@ -389,6 +396,12 @@ $.widget( "ui.selectmenu", {
}
},

_selectMenu: function( event ) {
if ( !this.menuItems.eq( this.focusIndex ).hasClass( "ui-state-disabled" ) ) {
this.menuInstance.select( event );
}
},

_select: function( item, event ) {
var oldIndex = this.element[ 0 ].selectedIndex;

0 comments on commit f3e4b24

Please sign in to comment.
You can’t perform that action at this time.