Kevin Powell - CommunityKP-C
Kevin Powell - Communityβ€’2y agoβ€’
7 replies
empty

problem with input type number

Hi guys, when the value of quantity is 0 and I enter 1 the input field display "01" while the quantity is 1. Can anyone help me explain why ? I'm using MUI. This case only occurs when I use type number. With type text, it worked
  const [quantity, setQuantity] = useState(0);
  const [stock, setStock] = useState(0);

  const handleOnChangeQuantity = (
    e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>
  ) => {
    if (!e.target.value) return setQuantity(0);
    if (+e.target.value > stock) return setQuantity(stock);
    setQuantity(+e.target.value);
  };

  <TextFieldCustom
                type="number"
                fullWidth
                value={quantity}
                onChange={handleOnChangeQuantity}
                className={styles["input-number"]}
                inputProps={{ min: 0, max: stock }}
   />
Was this page helpful?