Browse files

changed keylistener to keydown instead of keyup and stopped event whe…

…n enter/return so choosing an item with the keyboard wouldn't submit the form

Signed-off-by: Kyle Neath <kneath@gmail.com>
  • Loading branch information...
1 parent 88605f6 commit 89fc37b439e3fcd72993b5d84fee8b4fb3bffd4c Toby Sterrett committed with Jan 18, 2009
Showing with 26 additions and 25 deletions.
  1. +24 −24 spec/specs.js
  2. +2 −1 src/select_autocompleter.js
View
48 spec/specs.js
@@ -71,7 +71,7 @@ describe("Keyboard Interaction", {
'after each': function(){
input.value = '';
- input.fireEvent('keyup', {key: ' '});
+ input.fireEvent('keydown', {key: ' '});
input.fireEvent('blur');
},
@@ -84,49 +84,49 @@ describe("Keyboard Interaction", {
'should filter the list when characters are typed in': function(){
input.fireEvent('focus');
input.value = "kamr";
- input.fireEvent('keyup', {key: 'r'});
+ input.fireEvent('keydown', {key: 'r'});
value_of(dropdown.getElements('li')).should_have_at_most(1, "items");
},
'should move down the list when the down arrow is pressed': function(){
input.fireEvent('focus');
- input.fireEvent('keyup', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[0]);
- input.fireEvent('keyup', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[1]);
},
'should not go past the last item when the down arrow is pressed': function(){
input.fireEvent('focus');
value_of(dropdown.getElements('li')).should_have_at_most(6, "items");
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li').getLast());
},
'should move up the list when the down arrow is pressed': function(){
input.fireEvent('focus');
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[2]);
- input.fireEvent('keyup', {key: 'up'});
+ input.fireEvent('keydown', {key: 'up'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[1]);
- input.fireEvent('keyup', {key: 'up'});
+ input.fireEvent('keydown', {key: 'up'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[0]);
},
'should not go past the first item when the up arrow is pressed': function(){
input.fireEvent('focus');
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
- input.fireEvent('keyup', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
+ input.fireEvent('keydown', {key: 'down'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[2]);
- input.fireEvent('keyup', {key: 'up'});
- input.fireEvent('keyup', {key: 'up'});
- input.fireEvent('keyup', {key: 'up'});
- input.fireEvent('keyup', {key: 'up'});
+ input.fireEvent('keydown', {key: 'up'});
+ input.fireEvent('keydown', {key: 'up'});
+ input.fireEvent('keydown', {key: 'up'});
+ input.fireEvent('keydown', {key: 'up'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[0]);
},
@@ -136,7 +136,7 @@ describe("Keyboard Interaction", {
},
'should move the keyboard from where the mouse is hovering': function(){
dropdown.getElements('li')[2].fireEvent('mouseover');
- input.fireEvent('keyup', {key: 'up'});
+ input.fireEvent('keydown', {key: 'up'});
value_of(Instance.highlightedChoice).should_be(dropdown.getElements('li')[1]);
}
});
View
3 src/select_autocompleter.js
@@ -62,7 +62,7 @@ var SelectAutocompleter = new Class({
this.dropDown.setStyle('display', 'none');
this.element.addEvent('focus', this.onFocus.bind(this));
this.element.addEvent('blur', function(){ this.onBlur.delay(100, this); }.bind(this));
- this.element.addEvent('keyup', this.keyListener.bind(this));
+ this.element.addEvent('keydown', this.keyListener.bind(this));
// Hide the select tag
@@ -147,6 +147,7 @@ var SelectAutocompleter = new Class({
// Select an item through the keyboard
}else if (event.key == "return" || event.key == "enter"){
+ event.stop(); // to prevent the form from being submitted
this.termChosen = this.highlightedChoice.getAttribute('rawText');
this.element.blur();

0 comments on commit 89fc37b

Please sign in to comment.