aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.ui.selectmenu.js
diff options
context:
space:
mode:
authorFelix Nagel <info@felixnagel.com>2011-12-23 01:34:12 +0100
committerFelix Nagel <info@felixnagel.com>2011-12-23 01:34:12 +0100
commit3025c51821b3e1d2307cbc56f308de0fbd4f2dad (patch)
treef2c16b51c6439b497dd07156182d0629e21c0f15 /ui/jquery.ui.selectmenu.js
parent8e27345e5a1210587038df2d7ec94cc055ee65e6 (diff)
downloadjquery-ui-3025c51821b3e1d2307cbc56f308de0fbd4f2dad.tar.gz
jquery-ui-3025c51821b3e1d2307cbc56f308de0fbd4f2dad.zip
Selectmenu: fixed button keyboard event handling (follow-up)
Diffstat (limited to 'ui/jquery.ui.selectmenu.js')
-rw-r--r--ui/jquery.ui.selectmenu.js37
1 files changed, 23 insertions, 14 deletions
diff --git a/ui/jquery.ui.selectmenu.js b/ui/jquery.ui.selectmenu.js
index 0592c58d3..511760972 100644
--- a/ui/jquery.ui.selectmenu.js
+++ b/ui/jquery.ui.selectmenu.js
@@ -284,14 +284,23 @@ $.widget( "ui.selectmenu", {
return li.appendTo( ul );
},
- _move: function( event, direction, focusFirst ) {
- // focus is needed otherwise this.active is not set correctly in Menu
- if ( focusFirst ) {
- this.menu.menu( "focus", event, this._getSelectedItem() );
+ _move: function( direction, event ) {
+ if ( direction == "first" || direction == "last" ) {
+ // 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() );
+ }
+ // move to and focus next or prev item
+ this.menu.menu( direction, event );
+ }
+
+ // select if selectmenu is closed
+ if ( !this.isOpen ) {
+ this.menu.menu( "select", event );
}
- // without this.active set, first and last item are triggered
- this.menu.menu( direction, event );
- this.menu.menu( "select", event );
},
_getSelectedItem: function() {
@@ -322,7 +331,7 @@ $.widget( "ui.selectmenu", {
break;
case $.ui.keyCode.ENTER:
if ( this.isOpen ) {
- this.menu.menu( "select", this._getSelectedItem() );
+ this.menu.menu( "select", event );
}
break;
case $.ui.keyCode.SPACE:
@@ -331,29 +340,29 @@ $.widget( "ui.selectmenu", {
if ( event.altKey ) {
this._toggle( event );
} else {
- this._move( event, "previous", true );
+ this._move( "previous", event );
}
break;
case $.ui.keyCode.DOWN:
if ( event.altKey ) {
this._toggle( event );
} else {
- this._move( event, "next", true );
+ this._move( "next", event );
}
break;
case $.ui.keyCode.LEFT:
- this._move( event, "previous", true );
+ this._move( "previous", event );
break;
case $.ui.keyCode.RIGHT:
- this._move( event, "next", true );
+ this._move( "next", event );
break;
case $.ui.keyCode.HOME:
case $.ui.keyCode.PAGE_UP:
- this._move( event, "next" );
+ this._move( "first", event );
break;
case $.ui.keyCode.END:
case $.ui.keyCode.PAGE_DOWN:
- this._move( event, "previous" );
+ this._move( "last", event );
break;
default:
this.menu.trigger( event );