如何专注于第一个输入字段-Redux-Form

M1M*_*1M6 5 javascript redux redux-form react-redux

我正在尝试以任何形式将第一个输入字段设置为焦点。那么,实现这样的最佳实践是什么?我如何检查字段的类型?是文字,数字,复选框还是其他?

是通过听@redux-form 动作,然后分派焦点动作吗?

有人可以提出解决方案吗?

jma*_*eli 3

我认为对于redux-form (v6+),当前的技术水平是autoFocus<input />您想要自动聚焦的属性提供属性。

例子:

<Field component={renderFirstInput} type="text" />

const renderFirstInput = field => {
  return ( <input {...field.input} autoFocus /> )

}
Run Code Online (Sandbox Code Playgroud)

这是 Github 问题链接

您当然可以提供autoFocus道具作为field.input钥匙。