diff --git a/modules/angular2/src/render/dom/events/key_events.ts b/modules/angular2/src/render/dom/events/key_events.ts index ec11038a82..d95c4366f3 100644 --- a/modules/angular2/src/render/dom/events/key_events.ts +++ b/modules/angular2/src/render/dom/events/key_events.ts @@ -39,15 +39,16 @@ export class KeyEventsPlugin extends EventManagerPlugin { } static parseEventName(eventName: string) /* {'domEventName': string, 'fullKey': string} */ { - eventName = eventName.toLowerCase(); - var parts = eventName.split('.'); + var parts = eventName.toLowerCase().split('.'); + var domEventName = ListWrapper.removeAt(parts, 0); if ((parts.length === 0) || !(StringWrapper.equals(domEventName, 'keydown') || StringWrapper.equals(domEventName, 'keyup'))) { return null; } - var key = ListWrapper.removeLast(parts); + + var key = KeyEventsPlugin._normalizeKey(ListWrapper.removeLast(parts)); var fullKey = ''; ListWrapper.forEach(modifierKeys, (modifierName) => { @@ -94,4 +95,14 @@ export class KeyEventsPlugin extends EventManagerPlugin { } }; } + +static _normalizeKey(keyName: string): string { + // TODO: switch to a StringMap if the mapping grows too much + switch (keyName) { + case 'esc': + return 'escape'; + default: + return keyName; + } +} } diff --git a/modules/angular2/test/render/dom/events/key_events_spec.js b/modules/angular2/test/render/dom/events/key_events_spec.js index 6eba3c1c79..7ab50941d6 100644 --- a/modules/angular2/test/render/dom/events/key_events_spec.js +++ b/modules/angular2/test/render/dom/events/key_events_spec.js @@ -65,5 +65,10 @@ export function main() { }); + it('should alias esc to escape', () => { + expect(KeyEventsPlugin.parseEventName('keyup.control.esc')) + .toEqual(KeyEventsPlugin.parseEventName('keyup.control.escape')); + }); + }); }