From 91b86b5b780eb6c090c89eebd405f3487147e6da Mon Sep 17 00:00:00 2001 From: Kris-K-Dev <92114648+Kris-K-Dev@users.noreply.github.com> Date: Thu, 1 Sep 2022 08:57:36 -0600 Subject: [PATCH] #2180 The e letter allowed to paste into number fields (#2508) Co-authored-by: Roman Zabaluev Co-authored-by: Oleg Shur --- .../src/components/common/Input/Input.tsx | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/kafka-ui-react-app/src/components/common/Input/Input.tsx b/kafka-ui-react-app/src/components/common/Input/Input.tsx index 58a3bb92c8..d6c6416bfe 100644 --- a/kafka-ui-react-app/src/components/common/Input/Input.tsx +++ b/kafka-ui-react-app/src/components/common/Input/Input.tsx @@ -17,6 +17,7 @@ const Input: React.FC = ({ hookFormOptions, search, inputSize = 'L', + type, ...rest }) => { const methods = useFormContext(); @@ -28,10 +29,30 @@ const Input: React.FC = ({ inputSize={inputSize} {...methods.register(name, { ...hookFormOptions })} hasLeftIcon={!!search} + type={type} {...rest} + onKeyDown={(e) => { + if (type === 'number') { + if (e.key === 'e') { + e.preventDefault(); + } + } + }} + onPaste={(e) => { + if (type === 'number') { + e.preventDefault(); + const value = e.clipboardData.getData('Text'); + methods.setValue(name, value.replace(/[^\d.]/g, '')); + } + }} /> ) : ( - + )} );