@@ -570,14 +570,30 @@ $.widget("ui.selectmenu", {
570
570
return this . list . find ( '.' + this . widgetBaseClass + '-item-focus' ) ;
571
571
} ,
572
572
573
- _moveSelection : function ( amt ) {
574
- var currIndex = parseInt ( this . _selectedOptionLi ( ) . data ( 'index' ) , 10 ) ;
573
+ _moveSelection : function ( amt , recIndex ) {
574
+ var currIndex = parseInt ( this . _selectedOptionLi ( ) . data ( 'index' ) || 0 , 10 ) ;
575
575
var newIndex = currIndex + amt ;
576
576
// do not loop when using up key
577
- if ( newIndex >= 0 ) return this . _optionLis . eq ( newIndex ) . trigger ( 'mouseup' ) ;
577
+
578
+ if ( newIndex < 0 ) {
579
+ newIndex = 0 ;
580
+ }
581
+ if ( newIndex > this . _optionLis . size ( ) - 1 ) {
582
+ newIndex = this . _optionLis . size ( ) - 1 ;
583
+ }
584
+ //Occurs when a full loop has been made
585
+ if ( newIndex === recIndex ) { return false ; }
586
+
587
+ if ( this . _optionLis . eq ( newIndex ) . hasClass ( this . namespace + '-state-disabled' ) ) {
588
+ // if option at newIndex is disabled, call _moveFocus, incrementing amt by one
589
+ ( amt > 0 ) ? ++ amt : -- amt ;
590
+ this . _moveSelection ( amt , newIndex ) ;
591
+ } else {
592
+ return this . _optionLis . eq ( newIndex ) . trigger ( 'mouseup' ) ;
593
+ }
578
594
} ,
579
595
580
- _moveFocus : function ( amt ) {
596
+ _moveFocus : function ( amt , recIndex ) {
581
597
if ( ! isNaN ( amt ) ) {
582
598
var currIndex = parseInt ( this . _focusedOptionLi ( ) . data ( 'index' ) || 0 , 10 ) ;
583
599
var newIndex = currIndex + amt ;
@@ -592,14 +608,17 @@ $.widget("ui.selectmenu", {
592
608
if ( newIndex > this . _optionLis . size ( ) - 1 ) {
593
609
newIndex = this . _optionLis . size ( ) - 1 ;
594
610
}
611
+
612
+ //Occurs when a full loop has been made
613
+ if ( newIndex === recIndex ) { return false ; }
595
614
596
615
var activeID = this . widgetBaseClass + '-item-' + Math . round ( Math . random ( ) * 1000 ) ;
597
616
598
617
this . _focusedOptionLi ( ) . find ( 'a:eq(0)' ) . attr ( 'id' , '' ) ;
599
618
600
619
if ( this . _optionLis . eq ( newIndex ) . hasClass ( this . namespace + '-state-disabled' ) ) {
601
620
// if option at newIndex is disabled, call _moveFocus, incrementing amt by one
602
- ( amt > 0 ) ? amt ++ : amt -- ;
621
+ ( amt > 0 ) ? ++ amt : -- amt ;
603
622
this . _moveFocus ( amt , newIndex ) ;
604
623
} else {
605
624
this . _optionLis . eq ( newIndex ) . find ( 'a:eq(0)' ) . attr ( 'id' , activeID ) . focus ( ) ;
0 commit comments