有人知道为什么 TextField 中的自动对焦无法在带有按钮组件的打开对话框表单中工作吗?
<TextField
autoFocus
margin="dense"
id="name"
label="Email Address"
type="email"
fullWidth
variant="standard"
/>
参见这里,它正在工作!
参见这里,它不起作用!
但是如果您使用组件链接,它就可以工作! 请参阅这里!
看看这个:https://github.com/mui/material-ui/issues/33004#issuecomment-1455260156。 将
disableRestoreFocus
添加到 <Dialog>
对我有用!
这是一个例子。
disableRestoreFocus
属性。autoFocus
属性。<Dialog disableRestoreFocus {...otherProps}>
...
<TextField autoFocus {...otherProps}/>
</Dialog>