Permalink
Browse files

Menu: Support number pad keyboard input

Fixes #15031
Closes gh-1732
  • Loading branch information...
1 parent 1148aef commit ac9ca9e52c90da56b6846501800103605467f98b @fnagel fnagel committed with scottgonzalez Aug 17, 2016
Showing with 35 additions and 16 deletions.
  1. +31 −15 tests/unit/selectmenu/core.js
  2. +4 −1 ui/widgets/menu.js
@@ -341,23 +341,39 @@ $.each( [
} );
} );
- QUnit.test( "Selectmenu should reset when its parent form resets", function( assert ) {
- var ready = assert.async();
- assert.expect( 2 );
+QUnit.test( "Selectmenu should reset when its parent form resets", function( assert ) {
+ var ready = assert.async();
+ assert.expect( 2 );
- var element = $( "#speed" ).selectmenu(),
- widget = element.selectmenu( "widget" ),
- initialValue = element.val(),
- form = element.closest( "form" );
+ var element = $( "#speed" ).selectmenu(),
+ widget = element.selectmenu( "widget" ),
+ initialValue = element.val(),
+ form = element.closest( "form" );
- element.val( "Slower" );
- element.selectmenu( "refresh" );
- assert.equal( $.trim( widget.text() ), "Slower" );
- form[ 0 ].reset();
- setTimeout( function() {
- assert.equal( $.trim( widget.text() ), initialValue );
- ready();
- } );
+ element.val( "Slower" );
+ element.selectmenu( "refresh" );
+ assert.equal( $.trim( widget.text() ), "Slower" );
+ form[ 0 ].reset();
+ setTimeout( function() {
+ assert.equal( $.trim( widget.text() ), initialValue );
+ ready();
} );
+} );
+
+QUnit.test( "Number pad input should change value", function( assert ) {
+ var ready = assert.async();
+ assert.expect( 1 );
+
+ var element = $( "#number" ).selectmenu(),
+ button = element.selectmenu( "widget" );
+
+ button.simulate( "focus" );
+ button.simulate( "keydown", { keyCode: 101 } );
+
+ setTimeout( function() {
+ assert.equal( element.val(), 5 );
+ ready();
+ } );
+} );
} );
View
@@ -236,9 +236,12 @@ return $.widget( "ui.menu", {
default:
preventDefault = false;
prev = this.previousFilter || "";
- character = String.fromCharCode( event.keyCode );
skip = false;
+ // Support number pad values
+ character = event.keyCode >= 96 && event.keyCode <= 105 ?
+ ( event.keyCode - 96 ).toString() : String.fromCharCode( event.keyCode );
+
clearTimeout( this.filterTimer );
if ( character === prev ) {

0 comments on commit ac9ca9e

Please sign in to comment.