2023 / 09 / 22
TIL: Capture keydown events on DIV elements

How to capture keydown/keypress events on HTML elements that aren't inputs

frontend
vue

Just set the tabindex attribute, then you’ll be able to listen to keydown — or keyup, keypress — events like this:

<div tabindex="1" @keydown.esc="doSomething()">
  I can emit keydown events now!
</div>