From f3e4b24485a34c89ee4032605d853c1b3e0a4e7e Mon Sep 17 00:00:00 2001 From: Felix Nagel Date: Tue, 29 Oct 2013 19:52:54 +0100 Subject: Selectmenu: improve disabled item handling --- ui/jquery.ui.selectmenu.js | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) (limited to 'ui/jquery.ui.selectmenu.js') diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js index 800503c08..69f863108 100644 --- a/ui/jquery.ui.selectmenu.js +++ b/ui/jquery.ui.selectmenu.js @@ -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; -- cgit v1.2.3