如何解决嗨,我如何在使用箭头键浏览表格时保持焦点以便输入值?
我有一个带有输入字段的表格。如果您按箭头键,则会切换表格单元格中的位置,但我需要光标才能使焦点处于活动状态,以便之后我可以在每个位置输入值
public move(object: any) {
const inputToArray = this.inputs.toArray();
const cols = this.displayedColumns.length;// length of table columns
let index = inputToArray.findIndex((x) => x.element === object.element);
// console.log('Index found:',index);
switch (object.action) {//UP DOWN LEFT and RIGHT stand for the arrow keys
case 'UP':
index -= cols;// 1 position up
inputToArray[index].element.nativeElement.focus();//The focus was supposed to be active after going up,it does not work though.
break;
case 'DOWN':
index += cols;// 1 position down
break;
case 'LEFT':
index -= 1;// 1 position to the left
break;
case 'RIGHT':
index += 1;// 1 position to the right
break;
}
if (index >= 0 && index < this.inputs.length) {
console.log('Navigating to index:',index);
inputToArray[index].element.nativeElement.focus();//as long as you're in the table,you can activate the focus by clicking only per se. It doesn't work in the case paragraphs.
}
}
如果有有用的解决方案,我将不胜感激。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。