Selectmenu: fixed button keyboard event handling (follow-up)

This commit is contained in:
Felix Nagel 2011-12-23 01:34:12 +01:00
parent 8e27345e5a
commit 3025c51821

View File

@ -284,14 +284,23 @@ $.widget( "ui.selectmenu", {
return li.appendTo( ul ); return li.appendTo( ul );
}, },
_move: function( event, direction, focusFirst ) { _move: function( direction, event ) {
// focus is needed otherwise this.active is not set correctly in Menu if ( direction == "first" || direction == "last" ) {
if ( focusFirst ) { // set focus manually for first or last item
this.menu.menu( "focus", event, this.menu.find( "li" ).not( '.ui-selectmenu-optgroup' )[ direction ]() );
} else {
// if menu is closed we need to focus the element first to indicate correct element
if ( !this.isOpen ) {
this.menu.menu( "focus", event, this._getSelectedItem() ); this.menu.menu( "focus", event, this._getSelectedItem() );
} }
// without this.active set, first and last item are triggered // move to and focus next or prev item
this.menu.menu( direction, event ); this.menu.menu( direction, event );
}
// select if selectmenu is closed
if ( !this.isOpen ) {
this.menu.menu( "select", event ); this.menu.menu( "select", event );
}
}, },
_getSelectedItem: function() { _getSelectedItem: function() {
@ -322,7 +331,7 @@ $.widget( "ui.selectmenu", {
break; break;
case $.ui.keyCode.ENTER: case $.ui.keyCode.ENTER:
if ( this.isOpen ) { if ( this.isOpen ) {
this.menu.menu( "select", this._getSelectedItem() ); this.menu.menu( "select", event );
} }
break; break;
case $.ui.keyCode.SPACE: case $.ui.keyCode.SPACE:
@ -331,29 +340,29 @@ $.widget( "ui.selectmenu", {
if ( event.altKey ) { if ( event.altKey ) {
this._toggle( event ); this._toggle( event );
} else { } else {
this._move( event, "previous", true ); this._move( "previous", event );
} }
break; break;
case $.ui.keyCode.DOWN: case $.ui.keyCode.DOWN:
if ( event.altKey ) { if ( event.altKey ) {
this._toggle( event ); this._toggle( event );
} else { } else {
this._move( event, "next", true ); this._move( "next", event );
} }
break; break;
case $.ui.keyCode.LEFT: case $.ui.keyCode.LEFT:
this._move( event, "previous", true ); this._move( "previous", event );
break; break;
case $.ui.keyCode.RIGHT: case $.ui.keyCode.RIGHT:
this._move( event, "next", true ); this._move( "next", event );
break; break;
case $.ui.keyCode.HOME: case $.ui.keyCode.HOME:
case $.ui.keyCode.PAGE_UP: case $.ui.keyCode.PAGE_UP:
this._move( event, "next" ); this._move( "first", event );
break; break;
case $.ui.keyCode.END: case $.ui.keyCode.END:
case $.ui.keyCode.PAGE_DOWN: case $.ui.keyCode.PAGE_DOWN:
this._move( event, "previous" ); this._move( "last", event );
break; break;
default: default:
this.menu.trigger( event ); this.menu.trigger( event );