From 2df8110fa1c2ccd01a929e01f90eaa0c15c9058c Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 26 Jul 2021 18:16:07 +0300 Subject: [PATCH] Added prevent typing letters if the type is number for Safari & Firefox --- src/ReactCodeInput.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/ReactCodeInput.js b/src/ReactCodeInput.js index 88408b8..b33b1dc 100644 --- a/src/ReactCodeInput.js +++ b/src/ReactCodeInput.js @@ -153,6 +153,7 @@ class ReactCodeInput extends Component { } handleKeyDown(e) { + const isNumeric = /^\d*$/.test(e.key); const target = Number(e.target.dataset.id), nextTarget = this.textInput[target + 1], prevTarget = this.textInput[target - 1]; @@ -224,6 +225,11 @@ class ReactCodeInput extends Component { break; } + // Prevents typing letters if the type is number for Safari & Firefox + if (e.target.type === 'number' && !isNumeric) { + e.preventDefault(); + } + this.handleTouch(value); }