The trick you may encounter is that it is “down” versus “right” and “left,” etc. if you have content laid out in a table (using an HTML table) (3x3, like a tic-tac-toe board), and you are in the central cell ...
+-----+-----+-----+ | | 1 | | +-----+-----+-----+ | 2 | x | 3 | +-----+-----+-----+ | | 4 | | +-----+-----+-----+
the squares 1,2,3,4 will be where you move if you press up, left, right, down ... but in the DOM order they are determined in the order 1,2,3,4
thus, “down” you would need to know to skip “3” and go to “4” ... even worse, there can be any number of “focusable” elements between 3 and 4 if you have a large table. (my simple case is a 3x3 table, but you can have all kinds of nodes, trays, floating nodes, etc.)
HTML example:
<table> <tr> <td></td> <td>1</td> <td></td> </tr> <tr> <td>2</td> <td>x</td> <td>3</td> </tr> <tr> <td></td> <td>4</td> <td></td> </tr> </table>
You might be better off making every custom a button element in which it will be (or you can set) tabIndex ... and then you can use the arrows to move forward / backward (only) through the controls.
Otherwise, you will need to create something smart in order to know "geometrically" what is below, left, up ... from where you are.
source share