Skip to content

Commit da9beff

Browse files
author
Kubit
committed
Input prevent ignored keys been pasted
1 parent f7595ac commit da9beff

File tree

15 files changed

+107
-22
lines changed

15 files changed

+107
-22
lines changed

src/components/input/inputStandAlone.tsx

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,7 @@ const InputStandAloneComponent = (
124124
}}
125125
onFocus={props.onFocus}
126126
onKeyDown={props.onKeyDown}
127-
onPaste={e => {
128-
if (props.disabledCopyAndPaste) {
129-
e.preventDefault();
130-
}
131-
}}
127+
onPaste={props.onPaste}
132128
/>
133129
<InputIconStandAlone
134130
ref={

src/components/input/inputUnControlled.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const InputUnControlledComponent = <V extends string | unknown>(
1212
internalErrorExecution = INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR,
1313
disabledArrowUpDownInputNumber = false,
1414
disabledWheelMouse = true,
15+
disabledCopyAndPaste,
1516
errorExecution,
1617
keyValidation,
1718
min,
@@ -34,6 +35,7 @@ const InputUnControlledComponent = <V extends string | unknown>(
3435
onKeyDown,
3536
onError,
3637
onInternalErrors,
38+
onPaste,
3739
...props
3840
}: IInputUnControlled<V>,
3941
ref: React.ForwardedRef<HTMLInputElement | undefined>
@@ -48,6 +50,7 @@ const InputUnControlledComponent = <V extends string | unknown>(
4850
handleBlurInternal,
4951
handleFocusInternal,
5052
handleKeyDownInternal,
53+
handlePasteInternal,
5154
} = useInput({
5255
ref,
5356
errorExecution,
@@ -71,12 +74,14 @@ const InputUnControlledComponent = <V extends string | unknown>(
7174
formatNumber,
7275
locale,
7376
disabledWheelMouse,
77+
disabledCopyAndPaste,
7478
onBlur,
7579
onChange,
7680
onFocus,
7781
onKeyDown,
7882
onError,
7983
onInternalErrors,
84+
onPaste,
8085
});
8186

8287
return (
@@ -97,6 +102,7 @@ const InputUnControlledComponent = <V extends string | unknown>(
97102
onChange={handleChangeInternal}
98103
onFocus={handleFocusInternal}
99104
onKeyDown={handleKeyDownInternal}
105+
onPaste={handlePasteInternal}
100106
/>
101107
);
102108
};

src/components/input/types/input.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ export enum MASK_TYPE {
6868
export enum ERROR_EXECUTION {
6969
ON_CHANGE = 'onChange',
7070
ON_BLUR = 'onBlur',
71+
NONE = 'none',
7172
}
7273

7374
export enum INTERNAL_ERROR_EXECUTION {
7475
ON_CHANGE = 'onChange',
7576
ON_BLUR = 'onBlur',
7677
ON_CHANGE_ON_BLUR = 'onChangeOnBlur',
78+
NONE = 'none',
7779
}
7880

7981
export enum AUTOCAPITALIZE_TYPE {
@@ -401,6 +403,7 @@ export type IInputStandAlone = IInputComponents & {
401403
onChange?: React.ChangeEventHandler<HTMLInputElement>;
402404
onKeyDown?: React.KeyboardEventHandler<HTMLInputElement>;
403405
onClick?: React.MouseEventHandler<HTMLInputElement>;
406+
onPaste?: React.ClipboardEventHandler<HTMLInputElement>;
404407
};
405408

406409
type propsToOmit =

src/components/inputCounter/inputCounter.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const InputCounterComponent = React.forwardRef(
1313
{
1414
type = InputTypeType.TEXT,
1515
truncate = false,
16+
disabledCopyAndPaste,
1617
internalErrorExecution = INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR,
1718
errorExecution,
1819
keyValidation,
@@ -34,6 +35,7 @@ const InputCounterComponent = React.forwardRef(
3435
onKeyDown,
3536
onError,
3637
onInternalErrors,
38+
onPaste,
3739
ctv,
3840
...props
3941
}: IInputCounter<V>,
@@ -55,6 +57,7 @@ const InputCounterComponent = React.forwardRef(
5557
handleBlurInternal,
5658
handleFocusInternal,
5759
handleKeyDownInternal,
60+
handlePasteInternal,
5861
} = useInput({
5962
ref,
6063
errorExecution,
@@ -74,12 +77,14 @@ const InputCounterComponent = React.forwardRef(
7477
informationAssociated: informationAssociatedValue?.content,
7578
ignoreKeys,
7679
regex,
80+
disabledCopyAndPaste,
7781
onBlur,
7882
onChange,
7983
onFocus,
8084
onKeyDown,
8185
onError,
8286
onInternalErrors,
87+
onPaste,
8388
});
8489

8590
return (
@@ -101,6 +106,7 @@ const InputCounterComponent = React.forwardRef(
101106
onChange={handleChangeInternal}
102107
onFocus={handleFocusInternal}
103108
onKeyDown={handleKeyDownInternal}
109+
onPaste={handlePasteInternal}
104110
/>
105111
);
106112
}

src/components/inputCurrency/inputCurrency.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const InputCurrencyComponent = React.forwardRef(
2121
disabledArrowUpDownInputNumber = false,
2222
ignoreKeys = ['+', '-', 'e'],
2323
disabledWheelMouse = true,
24+
disabledCopyAndPaste,
2425
type = InputTypeType.NUMBER,
2526
max,
2627
errorExecution,
@@ -43,6 +44,7 @@ const InputCurrencyComponent = React.forwardRef(
4344
onKeyDown,
4445
onError,
4546
onInternalErrors,
47+
onPaste,
4648
ctv,
4749
...props
4850
}: IInputCurrency<V>,
@@ -62,6 +64,7 @@ const InputCurrencyComponent = React.forwardRef(
6264
handleBlurInternal,
6365
handleFocusInternal,
6466
handleKeyDownInternal,
67+
handlePasteInternal,
6568
} = useInput({
6669
ref,
6770
errorExecution,
@@ -86,12 +89,14 @@ const InputCurrencyComponent = React.forwardRef(
8689
formatNumber,
8790
locale,
8891
disabledWheelMouse,
92+
disabledCopyAndPaste,
8993
onBlur,
9094
onChange,
9195
onFocus,
9296
onKeyDown,
9397
onError,
9498
onInternalErrors,
99+
onPaste,
95100
});
96101

97102
return (
@@ -113,6 +118,7 @@ const InputCurrencyComponent = React.forwardRef(
113118
onChange={handleChangeInternal}
114119
onFocus={handleFocusInternal}
115120
onKeyDown={handleKeyDownInternal}
121+
onPaste={handlePasteInternal}
116122
/>
117123
);
118124
}

src/components/inputCurrency/stories/inputCurrency.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const commonArgs: IInputCurrency = {
4444
currencyPosition: POSITIONS.RIGHT,
4545
disabledArrowUpDownInputNumber: false,
4646
secondaryLabel: labelSecondary(themeSelected),
47+
ignoreKeys: ['+', '-', 'e', '.'],
4748
additionalInfo: additionalInfoAction(themeSelected),
4849
};
4950

src/components/inputDate/hooks/useInputDate.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,15 @@ export const useInputDate = ({
6969
type,
7070
truncate,
7171
informationAssociated,
72+
disabledCopyAndPaste,
7273
onWrapperBlur,
7374
onBlur,
7475
onChange,
7576
onFocus,
7677
onKeyDown,
7778
onError,
7879
onInternalErrors,
80+
onPaste,
7981
...props
8082
}: ParamsType): ReturnType => {
8183
// Ghost prototype
@@ -431,6 +433,7 @@ export const useInputDate = ({
431433
handleFocusInternal,
432434
handleKeyDownInternal,
433435
handleSetValue,
436+
handlePasteInternal,
434437
} = useInput({
435438
ref,
436439
keyValidation,
@@ -447,12 +450,14 @@ export const useInputDate = ({
447450
type,
448451
truncate,
449452
informationAssociated,
453+
disabledCopyAndPaste,
450454
onBlur,
451455
onFocus,
452456
onKeyDown,
453457
onError,
454458
onInternalErrors,
455459
onChange: handleChangeInternalValidate,
460+
onPaste,
456461
});
457462

458463
// update initial dates when they have value
@@ -516,5 +521,6 @@ export const useInputDate = ({
516521
handleFocusInternal,
517522
handleKeyDownInternal,
518523
handleSetValue,
524+
handlePasteInternal,
519525
};
520526
};

src/components/inputDropdown/hooks/useInputDropdown.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
ChangeEvent,
33
ChangeEventHandler,
4+
ClipboardEventHandler,
45
FocusEventHandler,
56
ForwardedRef,
67
KeyboardEventHandler,
@@ -58,6 +59,7 @@ type ParamsType = {
5859
hasInputInSearchList?: boolean;
5960
name?: string;
6061
internalErrorExecution?: INTERNAL_ERROR_EXECUTION;
62+
disabledCopyAndPaste?: boolean;
6163
onClick?: (
6264
event: React.KeyboardEvent<HTMLInputElement> | React.MouseEvent<HTMLInputElement, MouseEvent>
6365
) => void;
@@ -69,6 +71,7 @@ type ParamsType = {
6971
onFocus?: FocusEventHandler<HTMLInputElement>;
7072
onOpenCloseOptions?: (open: boolean) => void;
7173
onInternalErrors?: (errors: string[]) => void;
74+
onPaste?: ClipboardEventHandler<HTMLInputElement>;
7275
};
7376

7477
type ReturnHookType = {
@@ -91,6 +94,7 @@ type ReturnHookType = {
9194
state: InputState;
9295
handleFocusInternal: FocusEventHandler<HTMLInputElement>;
9396
handleInputPopoverChange: ChangeEventHandler<HTMLInputElement>;
97+
handlePasteInternal?: ClipboardEventHandler<HTMLInputElement>;
9498
};
9599

96100
export const useInputDropdown = (props: ParamsType): ReturnHookType => {
@@ -146,16 +150,18 @@ export const useInputDropdown = (props: ParamsType): ReturnHookType => {
146150
};
147151

148152
// Input Basic hook
149-
const { state, inputRef, handleFocusInternal } = useInput({
153+
const { state, inputRef, handleFocusInternal, handlePasteInternal } = useInput({
150154
internalErrorExecution: props.internalErrorExecution,
151155
disabled: props.disabled,
152156
error: props.error || internalErrors.length > 0,
153157
// need for update the state
154158
currentValue: searchText,
155159
informationAssociated: props.informationAssociated,
160+
disabledCopyAndPaste: props.disabledCopyAndPaste,
156161
onFocus: props.onFocus,
157162
onBlur: handleInputBlur,
158163
onInternalErrors: props.onInternalErrors,
164+
onPaste: props.onPaste,
159165
});
160166

161167
const useActionBottomSheet = useMemo(
@@ -388,5 +394,6 @@ export const useInputDropdown = (props: ParamsType): ReturnHookType => {
388394
listOptionsHeight,
389395
handleFocusInternal,
390396
handleInputPopoverChange,
397+
handlePasteInternal,
391398
};
392399
};

src/components/inputPassword/inputPassword.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const InputPasswordComponent = React.forwardRef(
2727
error,
2828
value: currentValue,
2929
ignoreKeys,
30+
disabledCopyAndPaste,
3031
onBlur,
3132
onChange,
3233
onFocus,
@@ -37,6 +38,7 @@ const InputPasswordComponent = React.forwardRef(
3738
disabledIcon,
3839
onInputTypeChange,
3940
onIconClick,
41+
onPaste,
4042
ctv,
4143
...props
4244
}: IInputPassword<V>,
@@ -73,6 +75,7 @@ const InputPasswordComponent = React.forwardRef(
7375
handleBlurInternal,
7476
handleFocusInternal,
7577
handleKeyDownInternal,
78+
handlePasteInternal,
7679
} = useInput({
7780
ref,
7881
errorExecution,
@@ -86,12 +89,14 @@ const InputPasswordComponent = React.forwardRef(
8689
currentValue,
8790
type: inputPasswordType,
8891
ignoreKeys,
92+
disabledCopyAndPaste,
8993
onBlur,
9094
onChange,
9195
onFocus,
9296
onKeyDown,
9397
onError,
9498
onInternalErrors,
99+
onPaste,
95100
});
96101

97102
const icon = inputPasswordType === InputTypeType.PASSWORD ? disabledIcon : activeIcon;
@@ -113,6 +118,7 @@ const InputPasswordComponent = React.forwardRef(
113118
onChange={handleChangeInternal}
114119
onFocus={handleFocusInternal}
115120
onKeyDown={handleKeyDownInternal}
121+
onPaste={handlePasteInternal}
116122
/>
117123
);
118124
}

src/components/inputPhone/inputPhone.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ const InputPhoneComponent = React.forwardRef(
2929
value: currentValue,
3030
informationAssociatedValue,
3131
ignoreKeys,
32+
disabledCopyAndPaste,
3233
onBlur,
3334
onChange,
3435
onFocus,
3536
onKeyDown,
3637
onError,
3738
onInternalErrors,
39+
onPaste,
3840
ctv,
3941
...props
4042
}: IInputPhone<V>,
@@ -50,6 +52,7 @@ const InputPhoneComponent = React.forwardRef(
5052
handleBlurInternal,
5153
handleFocusInternal,
5254
handleKeyDownInternal,
55+
handlePasteInternal,
5356
} = useInput({
5457
ref,
5558
errorExecution,
@@ -68,12 +71,14 @@ const InputPhoneComponent = React.forwardRef(
6871
truncate,
6972
informationAssociated: informationAssociatedValue?.content,
7073
ignoreKeys,
74+
disabledCopyAndPaste,
7175
onBlur,
7276
onChange,
7377
onFocus,
7478
onKeyDown,
7579
onError,
7680
onInternalErrors,
81+
onPaste,
7782
});
7883

7984
return (
@@ -94,6 +99,7 @@ const InputPhoneComponent = React.forwardRef(
9499
onChange={handleChangeInternal}
95100
onFocus={handleFocusInternal}
96101
onKeyDown={handleKeyDownInternal}
102+
onPaste={handlePasteInternal}
97103
/>
98104
);
99105
}

0 commit comments

Comments
 (0)