启用 redux-form 并将焦点设置为字段 [英] Enable redux-form and set focus to field

查看:58
本文介绍了启用 redux-form 并将焦点设置为字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

默认情况下我禁用了表单字段,当用户单击按钮 Edit 时,它将启用该字段.我也想把重点放在这个领域,但我不知道怎么做.我已经为该字段创建了 ref 并在其上尝试了一些 focus() 函数,但它没有工作.您可以在 sandbox 上试用.

I've got disabled form field by default and when user clicks on button Edit, it will enable the field. I also want to set focus on the field, but I don't know how. I've created ref to the field and tried some focus() function on it, but it hasn't worked. You can try it here on sandbox.

推荐答案

  1. 您必须将 ref 分配给 input 元素而不是 Field 组件
  2. 添加回调函数,在父组件中设置子组件输入的引用
  3. 在按下编辑按钮时使用引用来聚焦输入:

https://codesandbox.io/s/rlx390xn6m

这篇关于启用 redux-form 并将焦点设置为字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆