【发布时间】:2022-11-10 04:43:26
【问题描述】:
我将 MUI TextField 组件用作单个输入表单。当组件加载时,它有焦点,但没有光标开始输入。用户仍然必须单击输入以调出光标并开始输入。或者,用户可以点击tab键,光标出现。但是键入其他任何内容都不会激活光标或在 TextField 中注册任何字符。我尝试使用 autoFocus 属性,以及:answer 中的 inputRef={input => input && input.focus()}。
这是表格:
<FormControl variant="standard" fullWidth>
<TextField
id="new-comment"
label="Comment"
multiline
minRows={3}
maxRows={5}
focused={true}
value={comment}
onChange={updateCommentValue}
onKeyDown={keyPress}
/>
<Button onClick={saveComment}>
Comment
</Button>
</FormControl>
【问题讨论】:
标签: javascript reactjs material-ui focus textfield