如何专注于 `ag-Grid`,以便下一次按键是来自 `ag-Grid` 本身的关键事件

How to focus on `ag-Grid` so the next key press is an key event come from `ag-Grid` itself

我为 ag-Grid 制作了一些自定义导航组件。

一旦用户的操作发生,我想关注 ag-Grid 的行或单元格之一,就好像用户自己简单地单击了 ag-Grid 的单元格之一。

所以在这次对焦之后,下次我按Up/Down/Left/Right这样的键时,它被注册为ag-Grid的键盘交互事件(Keyboard Interaction: Core Feature of our Datagrid).

更具体地说,一旦按下箭头键,navigateToNextCell() 挂钩就会被调用。

我该怎么做?

我尝试过类似的东西:

None 这些东西奏效了。

给定行索引 index:

,关注行节点有效
const rowNode = document.querySelector(`.ag-row[row-index="${index}"] > .ag-cell`)
if (rowNode) {
  rowNode.focus()
}