Aurelia 2 keydown.trigger preventing default without a way to disable it

In Aurelia 1, we could disable the preventDefault() call that the framework does internally when binding keydown.trigger by returning true from the event handler. In v2, this doesn’t seem to work, returning true from the event handler will not stop Aurelia 2 from still calling preventDefault() on the keyboard event. This stops the pressed key from printing in the input control.

What’s also interesting is that using keydown.delegate instead seems to not call preventDefault() and solves my use-case, but I’m trying to prefer using .trigger instead as that is the preferred binding mechanism from what I understand.

Is there a different way to do this now?

HTML:

<input type="text" keydown.trigger="handleKey($event)" />

JS:

handleKey(ev: KeyboardEvent) {
   return true;
}
3 Likes

With Aurelia2 you can always do that with ev.preventDefault().

2 Likes