Fixes #2375 - event.key is now correctly set for F keys on keyup #2395

Merged
merged 1 commit into from Aug 8, 2012
View
@@ -36,7 +36,7 @@ var DOMEvent = this.DOMEvent = new Type('DOMEvent', function(event, win){
if (type.indexOf('key') == 0){
var code = this.code = (event.which || event.keyCode);
this.key = _keys[code]/*<1.3compat>*/ || Object.keyOf(Event.Keys, code)/*</1.3compat>*/;
- if (type == 'keydown'){
+ if (type == 'keydown' || type == 'keyup'){
if (code > 111 && code < 124) this.key = 'f' + (code - 111);
else if (code > 95 && code < 106) this.key = code - 96;
}
@@ -110,4 +110,32 @@ describe('Element.Event.change', function(){
});
+describe('Element.Event keyup with f<key>', function(){
+
+ it('should pass event.key == f2 when pressing f2 on keyup and keydown', function(){
+
+ var keydown = jasmine.createSpy('keydown');
+ var keyup = jasmine.createSpy('keyup');
+
+ var div = createElement('div')
+ .addEvent('keydown', function(event){
+ keydown(event.key);
+ })
+ .addEvent('keyup', function(event){
+ keyup(event.key);
+ })
+ .inject(document.body);
+
+ Syn.trigger('keydown', 'f2', div);
+ Syn.trigger('keyup', 'f2', div);
+
+ expect(keydown).toHaveBeenCalledWith('f2');
+ expect(keyup).toHaveBeenCalledWith('f2');
+
+ div.destroy();
+
+ });
+
+});
+
})();