#2180 The e letter allowed to paste into number fields (#2508)

Co-authored-by: Roman Zabaluev <rzabaluev@provectus.com>
Co-authored-by: Oleg Shur <workshur@gmail.com>
This commit is contained in:
Kris-K-Dev 2022-09-01 08:57:36 -06:00 committed by GitHub
parent 77dca1594c
commit 91b86b5b78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -17,6 +17,7 @@ const Input: React.FC<InputProps> = ({
hookFormOptions, hookFormOptions,
search, search,
inputSize = 'L', inputSize = 'L',
type,
...rest ...rest
}) => { }) => {
const methods = useFormContext(); const methods = useFormContext();
@ -28,10 +29,30 @@ const Input: React.FC<InputProps> = ({
inputSize={inputSize} inputSize={inputSize}
{...methods.register(name, { ...hookFormOptions })} {...methods.register(name, { ...hookFormOptions })}
hasLeftIcon={!!search} hasLeftIcon={!!search}
type={type}
{...rest} {...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, ''));
}
}}
/> />
) : ( ) : (
<S.Input inputSize={inputSize} hasLeftIcon={!!search} {...rest} /> <S.Input
inputSize={inputSize}
hasLeftIcon={!!search}
type={type}
{...rest}
/>
)} )}
</S.Wrapper> </S.Wrapper>
); );