Ввод пароля не отличается от других текстовых вводов.Сначала вы должны создать ссылку на вход, затем вы можете вызвать его метод focus()
в любой точке, чтобы сфокусировать ввод.Приведенный ниже код фокусирует ввод, когда компонент монтируется:
import React from "react";
import ReactDOM from "react-dom";
import { Icon, Input } from "antd";
import "antd/dist/antd.css";
import "./index.css";
class LoginForm extends React.Component {
passwordInput = null;
componentDidMount() {
this.passwordInput.focus();
}
render() {
return (
<div className="App">
<Input
prefix={<Icon type="lock" style={{ color: "rgba(0,0,0,.25)" }} />}
type="password"
placeholder="Password"
ref={input => {
this.passwordInput = input;
}}
/>
</div>
);
}
}
ReactDOM.render(<LoginForm />, document.getElementById("root"));
Попробуйте здесь