Focusing input box programatically from another co

2019-09-01 02:13发布

I had a question where the (great) answer exemplified how to allow an input box to obtain focus (by requesting change detection to be run in case the component isn't visible at the moment of focus assignment).

Now, I'm faced with a similar problem. I'm setting the value in a field of the component that contains the input box from another component. It works as far I can see the input box being displayed and the read-only label getting hidden. However, the input box isn't focused on.

I'm suspecting that the reason for it is the same, or least similar. However, since I'm setting the value from outside of the component, I can't rely on accessing it as a view child anymore, as I did in the case of the click handler.

What would be an appropriate strategy to approach it?

The usual googling rendered no useful links. I'm not providing a sample because, frankly, I'm not sure how to illustrate the issue other than describe it in words.

onUpdate(config: DataRowConfig) {
  const target = config.cellConfigs.find(a => a.justSubmitted);
  const index = config.cellConfigs.findIndex(a => a.justSubmitted);
  if (target.key === "Enter")
    config.cellConfigs[(column + 1) % 5].editing = true;
}

0条回答
登录 后发表回答