mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Merge branch 'menuaria' into master
This commit is contained in:
commit
58a120bb4b
@ -251,6 +251,22 @@
|
|||||||
</blockquote>
|
</blockquote>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<ul id="menu6">
|
||||||
|
<li class="foo"><a class="foo" href="#">Aberdeen</a></li>
|
||||||
|
<li class="foo ui-state-disabled"><a class="foo" href="#">Ada</a></li>
|
||||||
|
<li class="foo"><a class="foo" href="#">Adamsville</a></li>
|
||||||
|
<li class="foo"><a class="foo" href="#">Addyston</a></li>
|
||||||
|
<li class="ui-state-disabled">
|
||||||
|
<a href="#">Delphi</a>
|
||||||
|
<ul>
|
||||||
|
<li class="foo"><a class="foo" href="#">Ada</a></li>
|
||||||
|
<li class="foo"><a class="foo" href="#">Saarland</a></li>
|
||||||
|
<li class="foo"><a class="foo" href="#">Salzburg</a></li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
<li class="foo"><a class="foo" href="#">Saarland</a></li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
<div id="log"></div>
|
<div id="log"></div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
@ -467,4 +467,56 @@ asyncTest("handle keyboard navigation on menu with scroll and with submenus", fu
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
asyncTest("handle keyboard navigation and mouse click on menu with disabled items", function() {
|
||||||
|
expect(6);
|
||||||
|
var element = $('#menu6').menu({
|
||||||
|
select: function(event, ui) {
|
||||||
|
menu_log($(ui.item[0]).text());
|
||||||
|
},
|
||||||
|
focus: function( event, ui ) {
|
||||||
|
menu_log($(event.target).find(".ui-state-focus").parent().index());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
menu_log("keydown",true);
|
||||||
|
element.one( "menufocus", function( event, ui ) {
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
||||||
|
equal( $("#log").html(), "1,keydown,", "Keydown focus but not select disabled item");
|
||||||
|
setTimeout( menukeyboard1, 50 );
|
||||||
|
});
|
||||||
|
element.focus();
|
||||||
|
|
||||||
|
|
||||||
|
function menukeyboard1() {
|
||||||
|
menu_log("keydown",true);
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } );
|
||||||
|
equal( $("#log").html(), "4,3,2,keydown,", "Keydown focus disabled item with submenu");
|
||||||
|
|
||||||
|
menu_log("keydown",true);
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
|
||||||
|
equal( $("#log").html(), "keydown,", "Keydown LEFT (no effect)");
|
||||||
|
|
||||||
|
menu_log("keydown",true);
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
equal( $("#log").html(), "keydown,", "Keydown RIGHT (no effect on disabled sub-menu)");
|
||||||
|
|
||||||
|
menu_log("keydown",true);
|
||||||
|
element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } );
|
||||||
|
|
||||||
|
setTimeout( function() {
|
||||||
|
equal( $("#log").html(), "keydown,", "Keydown ENTER (no effect on disabled sub-menu)");
|
||||||
|
menu_log("click",true);
|
||||||
|
menu_click( element, "1" );
|
||||||
|
equal( $("#log").html(), "click,", "Click disabled item (no effect)");
|
||||||
|
start();
|
||||||
|
}, 50);
|
||||||
|
}, 50);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@ -118,7 +118,7 @@
|
|||||||
<li class="ui-state-disabled"><a href="#"><span class="ui-icon ui-icon-scissors"></span>Ada</a></li>
|
<li class="ui-state-disabled"><a href="#"><span class="ui-icon ui-icon-scissors"></span>Ada</a></li>
|
||||||
<li><a href="#">Adamsville</a></li>
|
<li><a href="#">Adamsville</a></li>
|
||||||
<li><a href="#"><span class="ui-icon ui-icon-wrench"></span>Addyston</a></li>
|
<li><a href="#"><span class="ui-icon ui-icon-wrench"></span>Addyston</a></li>
|
||||||
<li>
|
<li class="ui-state-disabled">
|
||||||
<a href="#">Delphi</a>
|
<a href="#">Delphi</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="#">Ada</a></li>
|
<li><a href="#">Ada</a></li>
|
||||||
|
23
ui/jquery.ui.menu.js
vendored
23
ui/jquery.ui.menu.js
vendored
@ -99,7 +99,7 @@ $.widget( "ui.menu", {
|
|||||||
"mouseleave .ui-menu": "collapseAll",
|
"mouseleave .ui-menu": "collapseAll",
|
||||||
"focus": function( event ) {
|
"focus": function( event ) {
|
||||||
var menu = this.element,
|
var menu = this.element,
|
||||||
firstItem = menu.children( ".ui-menu-item" ).not( ".ui-state-disabled" ).eq( 0 );
|
firstItem = menu.children( ".ui-menu-item" ).eq( 0 );
|
||||||
if ( this._hasScroll() && !this.active ) {
|
if ( this._hasScroll() && !this.active ) {
|
||||||
menu.children().each(function() {
|
menu.children().each(function() {
|
||||||
var currentItem = $( this );
|
var currentItem = $( this );
|
||||||
@ -196,16 +196,19 @@ $.widget( "ui.menu", {
|
|||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
case $.ui.keyCode.RIGHT:
|
case $.ui.keyCode.RIGHT:
|
||||||
|
if ( !this.active.is( ".ui-state-disabled" ) ) {
|
||||||
this.expand( event );
|
this.expand( event );
|
||||||
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
case $.ui.keyCode.ENTER:
|
case $.ui.keyCode.ENTER:
|
||||||
|
if ( !this.active.is( ".ui-state-disabled" ) ) {
|
||||||
if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
|
if ( this.active.children( "a[aria-haspopup='true']" ).length ) {
|
||||||
this.expand( event );
|
this.expand( event );
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this.select( event );
|
this.select( event );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
break;
|
break;
|
||||||
case $.ui.keyCode.ESCAPE:
|
case $.ui.keyCode.ESCAPE:
|
||||||
@ -442,7 +445,6 @@ $.widget( "ui.menu", {
|
|||||||
this.active
|
this.active
|
||||||
.children( ".ui-menu " )
|
.children( ".ui-menu " )
|
||||||
.children( ".ui-menu-item" )
|
.children( ".ui-menu-item" )
|
||||||
.not( ".ui-state-disabled" )
|
|
||||||
.first();
|
.first();
|
||||||
|
|
||||||
if ( newItem && newItem.length ) {
|
if ( newItem && newItem.length ) {
|
||||||
@ -478,12 +480,10 @@ $.widget( "ui.menu", {
|
|||||||
if ( direction === "first" || direction === "last" ) {
|
if ( direction === "first" || direction === "last" ) {
|
||||||
next = this.active
|
next = this.active
|
||||||
[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
|
[ direction === "first" ? "prevAll" : "nextAll" ]( ".ui-menu-item" )
|
||||||
.not( ".ui-state-disabled" )
|
|
||||||
.eq( -1 );
|
.eq( -1 );
|
||||||
} else {
|
} else {
|
||||||
next = this.active
|
next = this.active
|
||||||
[ direction + "All" ]( ".ui-menu-item" )
|
[ direction + "All" ]( ".ui-menu-item" )
|
||||||
.not( ".ui-state-disabled" )
|
|
||||||
.eq( 0 );
|
.eq( 0 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -492,9 +492,6 @@ $.widget( "ui.menu", {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.focus( event, next );
|
this.focus( event, next );
|
||||||
if ( next.is( ".ui-state-disabled" ) ) {
|
|
||||||
this._move( direction, filter, event );
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
|
|
||||||
nextPage: function( event ) {
|
nextPage: function( event ) {
|
||||||
@ -509,14 +506,14 @@ $.widget( "ui.menu", {
|
|||||||
var base = this.active.offset().top,
|
var base = this.active.offset().top,
|
||||||
height = this.element.height(),
|
height = this.element.height(),
|
||||||
result;
|
result;
|
||||||
this.active.nextAll( ".ui-menu-item" ).not( ".ui-state-disabled" ).each(function() {
|
this.active.nextAll( ".ui-menu-item" ).each(function() {
|
||||||
result = $( this );
|
result = $( this );
|
||||||
return $( this ).offset().top - base - height < 0;
|
return $( this ).offset().top - base - height < 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.focus( event, result );
|
this.focus( event, result );
|
||||||
} else {
|
} else {
|
||||||
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).not( ".ui-state-disabled" )
|
this.focus( event, this.activeMenu.children( ".ui-menu-item" )
|
||||||
[ !this.active ? "first" : "last" ]() );
|
[ !this.active ? "first" : "last" ]() );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -533,14 +530,14 @@ $.widget( "ui.menu", {
|
|||||||
var base = this.active.offset().top,
|
var base = this.active.offset().top,
|
||||||
height = this.element.height(),
|
height = this.element.height(),
|
||||||
result;
|
result;
|
||||||
this.active.prevAll( ".ui-menu-item" ).not( ".ui-state-disabled" ).each(function() {
|
this.active.prevAll( ".ui-menu-item" ).each(function() {
|
||||||
result = $( this );
|
result = $( this );
|
||||||
return $(this).offset().top - base + height > 0;
|
return $(this).offset().top - base + height > 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.focus( event, result );
|
this.focus( event, result );
|
||||||
} else {
|
} else {
|
||||||
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).not( ".ui-state-disabled" ).first() );
|
this.focus( event, this.activeMenu.children( ".ui-menu-item" ).first() );
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user