Keyboard Controls for Autocomplete

Use OnKeyDown to listen for arrow keys, not OnKeyPress!

ยท

1 min read

One of today's tasks was to add autocomplete to my project's search bar. So, when you type, a box should appear below the input box to show potential things you might want to search for.

I discovered today the following things:

1 - It's needless to set up an EventListener when you can just use HTML's own properties for it.

2 - OnKeyPress works great for characters and the enter key, but doesn't catch other keys

3 - OnKeyDown can be used to listen for arrow keys, which are returned on the event as such: event.key ==="ArrowUp"

That's all for now~!

When I come up with other, cooler things, I'll be sure to post.

ย