I have implemented arrow key navigation in a table, allowing navigation with the up, down, left, and right arrow keys. How can I ensure that the cursor always stays on the right side of the input field during navigation?
Check out my Stackblitz example here: https://stackblitz.com/edit/stackoverflow-72056135-ube6hj?file=app%2Ftable-basic-example.ts
Here is a snippet of my code:
// HTML
<input class="edit-input || focus-cell" type="text"[formControl]="rowControl.get(column.attribute)" appArrowKeyNav>
// TS
/**
* Use arrowKeys
* @param object any
*/
move(object) {
const inputToArray = this.inputs.toArray();
let index = inputToArray.findIndex((x) => x.element === object.element);
switch (object.action) {
case 'UP':
index -= this.columns.length;
break;
case 'DOWN':
index += this.columns.length;
break;
case 'LEFT':
index--;
break;
case 'RIGTH':
index++;
break;
}
if (index >= 0 && index < this.inputs.length) {
inputToArray[index].element.nativeElement.focus();
}
}