I have the following problem: I have an input textbox and I am scanning a barcode. But the textbox doesn't close automatically. If I enter numbers using the keyboard it automatically closes. Did I do something wrong? Is the scanner too fast? Any ideas?
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" />
P粉4861381962023-09-09 16:29:06
Do this:
<TextField autoFocus onChange={onValueChange} margin="dense" id="number" type="text" inputProps={{minlength: 16,maxlength:16}} fullWidth variant="outlined" onBlur={() => setOpen(false)} /* NEW */ />