Skip to content
Permalink
Browse files

Menu: Prevent navigating to disabled menu items with the keyboard.

  • Loading branch information
kborchers committed Feb 6, 2012
1 parent 30713ad commit 87dc9ce24a6355ea551b9dfc266b84712fd5d00c
Showing with 23 additions and 23 deletions.
  1. +3 −2 tests/visual/menu/menu.html
  2. +20 −21 ui/jquery.ui.menu.js
@@ -74,9 +74,9 @@
</ul>

<ul id="menu2">
<li><a href="#">Aberdeen</a></li>
<li class="ui-state-disabled"><a href="#">Aberdeen</a></li>
<li><a href="#">Ada</a></li>
<li class="ui-state-disabled"><a href="#">Adamsville</a></li>
<li><a href="#">Adamsville</a></li>
<li><a href="#">Addyston</a></li>
<li>
<a href="#">Delphi</a>
@@ -109,6 +109,7 @@
<li><a href="#">Perch</a></li>
</ul>
</li>
<li class="ui-state-disabled"><a href="#">Amesville</a></li>
</ul>

<ul id="menu3">
@@ -77,7 +77,7 @@ $.widget( "ui.menu", {
"mouseleave": "collapseAll",
"mouseleave .ui-menu": "collapseAll",
"focus": function( event ) {
var firstItem = this.element.children( ".ui-menu-item" ).eq( 0 );
var firstItem = this.element.children( ".ui-menu-item" ).not( ".ui-state-disabled" ).eq( 0 );
if ( this._hasScroll() && !this.active ) {
var menu = this.element;
menu.children().each( function() {
@@ -417,7 +417,7 @@ $.widget( "ui.menu", {
},

expand: function( event ) {
var newItem = this.active && this.active.children( ".ui-menu " ).children( ".ui-menu-item" ).first();
var newItem = this.active && this.active.children( ".ui-menu " ).children( ".ui-menu-item" ).not( ".ui-state-disabled" ).first();

if ( newItem && newItem.length ) {
this._open( newItem.parent() );
@@ -447,28 +447,27 @@ $.widget( "ui.menu", {
},

_move: function( direction, filter, event ) {
if ( !this.active ) {
this.focus( event, this.activeMenu.children( ".ui-menu-item" )[ filter ]() );
return;
}

var next;
if ( direction === "first" || direction === "last" ) {
next = this.active[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" ).eq( -1 );
} else {
next = this.active[ direction + "All" ]( ".ui-menu-item" ).eq( 0 );
if ( this.active ) {
if ( direction === "first" || direction === "last" ) {
next = this.active[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" ).not( ".ui-state-disabled" ).eq( -1 );
} else {
next = this.active[ direction + "All" ]( ".ui-menu-item" ).not( ".ui-state-disabled" ).eq( 0 );
}
}
if ( !next.length || !this.active ) {
next = this.activeMenu.children( ".ui-menu-item" )[ filter ]();
}

if ( next.length ) {
this.focus( event, next );
} else {
this.focus( event, this.activeMenu.children( ".ui-menu-item" )[ filter ]() );
this.focus( event, next );
if ( next.is( ".ui-state-disabled" ) ) {
this._move( direction, filter, event );
}
},

nextPage: function( event ) {
if ( !this.active ) {
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
this._move( "next", "first", event );
return;
}
if ( this.isLastItem() ) {
@@ -478,21 +477,21 @@ $.widget( "ui.menu", {
var base = this.active.offset().top,
height = this.element.height(),
result;
this.active.nextAll( ".ui-menu-item" ).each( function() {
this.active.nextAll( ".ui-menu-item" ).not( ".ui-state-disabled" ).each( function() {
result = $( this );
return $( this ).offset().top - base - height < 0;
});

this.focus( event, result );
} else {
this.focus( event, this.activeMenu.children( ".ui-menu-item" )
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).not( ".ui-state-disabled" )
[ !this.active ? "first" : "last" ]() );
}
},

previousPage: function( event ) {
if ( !this.active ) {
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
this._move( "next", "first", event );
return;
}
if ( this.isFirstItem() ) {
@@ -502,14 +501,14 @@ $.widget( "ui.menu", {
var base = this.active.offset().top,
height = this.element.height(),
result;
this.active.prevAll( ".ui-menu-item" ).each( function() {
this.active.prevAll( ".ui-menu-item" ).not( ".ui-state-disabled" ).each( function() {
result = $( this );
return $(this).offset().top - base + height > 0;
});

this.focus( event, result );
} else {
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).not( ".ui-state-disabled" ).first() );
}
},

0 comments on commit 87dc9ce

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