Close input text box: ReactJs operation when value changes
P粉386318086
P粉386318086 2023-09-08 23:29:17
0
1
630

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粉386318086
P粉386318086

reply all(1)
P粉486138196

Do this:

<TextField autoFocus 
onChange={onValueChange} 
margin="dense" 
id="number"  
type="text" 
inputProps={{minlength: 16,maxlength:16}} 
fullWidth 
variant="outlined"
onBlur={() => setOpen(false)} /* NEW */
 />
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template