I have a list of elements with the class .node-display
, when one is clicked it becomes an input. I want to capture the down or up arrow keyups to click the very next .node-display
in the list (relative to the current element).
In the below example, pressing down should click on item 5, and pressing up would click on item 3.
- 1
- 2
- 3
- 4 (Currently selected)
- 5
- 6
My best guess is something like this.
<input
_="on keyup[key is 'ArrowDown'] send click to the first .node-display end"
>
Does anyone know how I'd actually write this expression?
You probably want to put the behavior on the parent
ul
so you don't have to repeat it on every input.Something like this:
Some notes on this code:
from
from in the event handler, which puts the element that the event came from into theit
symbolkeydown
event so we can cancel the event with thehalt
command, to avoid the down and up keys changing the caret positionhalt
command to stop the event from propogatingfocus
rather than click as a proof of concept