单击按钮后如何聚焦文本字段 . 我试图使用autoFocus,但它没有成功:Example sandbox
<div>
<button onclick={() => this.setState({ focus: true })}>
Click to focus Textfield
</button>
<TextField
label="My Textfield"
id="mui-theme-provider-input"
autoFocus={this.state.focus}
/>
</div>
1 回答
你需要使用ref,参见https://reactjs.org/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element