mirror of
https://github.com/vercel/commerce.git
synced 2025-06-18 21:21:21 +00:00
Improve quantity input behavior in cart item
This commit is contained in:
parent
bef569619f
commit
601ec01b96
@ -35,7 +35,7 @@ const CartItem = ({
|
||||
|
||||
const updateItem = useUpdateItem({ item })
|
||||
const removeItem = useRemoveItem()
|
||||
const [quantity, setQuantity] = useState(item.quantity)
|
||||
const [quantity, setQuantity] = useState<number | ''>(item.quantity)
|
||||
const [removing, setRemoving] = useState(false)
|
||||
|
||||
const updateQuantity = async (val: number) => {
|
||||
@ -43,10 +43,10 @@ const CartItem = ({
|
||||
}
|
||||
|
||||
const handleQuantity = (e: ChangeEvent<HTMLInputElement>) => {
|
||||
const val = Number(e.target.value)
|
||||
const val = !e.target.value ? '' : Number(e.target.value)
|
||||
|
||||
if (Number.isInteger(val) && val >= 0) {
|
||||
setQuantity(Number(e.target.value))
|
||||
if (!val || (Number.isInteger(val) && val >= 0)) {
|
||||
setQuantity(val)
|
||||
}
|
||||
}
|
||||
const handleBlur = () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user