Speaking of number scrubbing (i.e. adding mouse UX to number inputs), you can also add better keyboard commands to number inputs. Kilian Valkhof explains how he added up and down arrows to a number input, as well as modifier keys to change how much the keys increment the value, like Emmet does.
This would make a nice little web component.
I just want to note that
keyCode
is no longer recommended. Bothcode
andkey
proprieties in the keyboard events have wide browser support (except, of course, Internet Explorer).A quick note:
code
ignores the keyboard layout. As an example pressing either/
orq
will returnKeyQ
on mine. Be careful to avoid unexpected bugs such as writing “press / to open search” and suddenly it don’t working in a different keyboard layout.Thanks, That’s much better than magic numbers too. I’ll amend the article!