我有以下问题:我有一个输入文本框,并且正在扫描条形码。但是文本框不会自动关闭。如果我用键盘输入数字,它会自动关闭。我做错了什么吗?扫描仪太快了吗?有什么想法吗?
const [open, setOpen] = useState(false);
const onValueChange = (event) => {
if(event.target.value.length===16){
setOpen(false);
}
};
<TextField autoFocus onChange={onValueChange} margin="dense" id="number" type="text" inputProps={{minlength: 16,maxlength:16}} fullWidth variant="outlined" /> Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
Do this:
<TextField autoFocus onChange={onValueChange} margin="dense" id="number" type="text" inputProps={{minlength: 16,maxlength:16}} fullWidth variant="outlined" onBlur={() => setOpen(false)} /* NEW */ />