From ce2f82285482d1272486c1f7af06874741057b29 Mon Sep 17 00:00:00 2001 From: Alex Vladut Date: Tue, 1 Jun 2021 12:06:14 +0300 Subject: [PATCH] fix: allow writing over when text is selected --- src/usePaymentInputs.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/usePaymentInputs.js b/src/usePaymentInputs.js index 8398b93..8da2699 100644 --- a/src/usePaymentInputs.js +++ b/src/usePaymentInputs.js @@ -142,7 +142,7 @@ export default function usePaymentCard({ if (!utils.validator.isNumeric(e)) { e.preventDefault(); } - if (utils.validator.hasCardNumberReachedMaxLength(cardNumber)) { + if (utils.validator.hasCardNumberReachedMaxLength(cardNumber) && e.target.selectionStart === e.target.selectionEnd) { e.preventDefault(); } } @@ -234,7 +234,7 @@ export default function usePaymentCard({ if (!utils.validator.isNumeric(e)) { e.preventDefault(); } - if (expiryDate.length >= 4) { + if (expiryDate.length >= 4 && e.target.selectionStart === e.target.selectionEnd) { e.preventDefault(); } } @@ -332,10 +332,10 @@ export default function usePaymentCard({ if (!utils.validator.isNumeric(e)) { e.preventDefault(); } - if (cardType && cvc.length >= cardType.code.length) { + if (cardType && cvc.length >= cardType.code.length && e.target.selectionStart === e.target.selectionEnd) { e.preventDefault(); } - if (cvc.length >= 4) { + if (cvc.length >= 4 && e.target.selectionStart === e.target.selectionEnd) { e.preventDefault(); } }