Skip to content

Menubar: move to next item applied focus() to too many items #953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions tests/unit/menubar/menubar_core.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,30 @@ test( "accessibility", function () {
ok( !element.attr( "aria-activedescendant" ), "aria-activedescendant not set" );
});

test( "Cursor keys should move the focus", function() {
expect( 3 );

var element = $( "#bar1" ).menubar(),
firstMenuItem = $( "#bar1 .ui-menubar-item .ui-button:first" );

firstMenuItem[ 0 ].focus();
equal( document.activeElement, firstMenuItem[0], "Focus set on first menuItem" );
$( firstMenuItem ).simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } );
ok( !firstMenuItem.hasClass( "ui-state-focus" ), "RIGHT should move focus off of focused item" );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );
equal( document.activeElement, firstMenuItem[0], "LEFT should return focus first menuItem" );
});

test ( "_destroy should successfully unwrap 'span.ui-button-text' elements" , function() {
expect(1);

var containedButtonTextSpans,
element = $( "#bar1" ).menubar();

element.menubar( "destroy" );
containedButtonTextSpans = element.find( "span.ui-button-text" ).length
equal( containedButtonTextSpans, 0, "All 'span.ui-button-text' should be removed by destroy" );
});


})( jQuery );
24 changes: 23 additions & 1 deletion tests/unit/menubar/menubar_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,29 @@ test( "hover over a menu item with no sub-menu should close open menu", function
menuItemWithDropdown.trigger("click");
menuItemWithoutDropdown.trigger("click");

equal($(".ui-menu:visible").length, 0, "After triggering a sub-menu, a click on a peer menu item should close the opened sub-menu");
equal($(".ui-menu:visible").length, 0, "After triggering a sub-menu, a click on a peer menu item should close the opened sub-menu");
});

test( "Cursor keys should move focus within the menu items", function() {
expect( 6 );

var element = $( "#bar1" ).menubar(),
firstMenuItem = $( "#bar1 .ui-menubar-item .ui-button:first" ),
nextLeftwardMenuElement = firstMenuItem.parent().siblings().last().children().eq( 0 );

equal( element.find( ":tabbable" ).length, 1, "A Menubar should have 1 tabbable element on init." );
firstMenuItem[ 0 ].focus();

ok( firstMenuItem.hasClass( "ui-state-focus" ), "After a focus event, the first element should have the focus class." );
$( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } );


ok( !firstMenuItem.hasClass( "ui-state-focus" ), "After a keypress event, the first element, should no longer have the focus class." );
ok( nextLeftwardMenuElement.hasClass( "ui-state-focus" ), "After a LEFT cursor event from the first element, the last element should have focus." );
equal( element.find( ":tabbable" ).length, 1, "A Menubar, after a cursor key action, should have 1 tabbable." );
equal( element.find( ":tabbable" )[ 0 ], nextLeftwardMenuElement[ 0 ], "A Menubar, after a cursor key action, should have 1 tabbable." );

} );


})( jQuery );
Loading