Skip to content

Commit 95db14e

Browse files
author
Kubit
committed
Enhance Input Component with internalErrorExecution Prop for Flexible Validation
This update introduces the internalErrorExecution prop to the Input component, offering enhanced control over the timing of internal error validation, particularly for email inputs. By default set to onChangeOnBlur, this new optional property allows developers to specify if the internal email validation should trigger on blur events, providing greater flexibility in error handling and improving user experience by reducing the frequency of validation messages during input.
1 parent 0486d14 commit 95db14e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/hooks/useInput/types/inputHook.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { FormatNumber, InputState, InputTypeType, MASK_TYPE } from '@/components
1111
export type ParamsTypeInputHook = {
1212
ref?: ForwardedRef<HTMLInputElement | undefined>;
1313
errorExecution?: string;
14+
internalErrorExecution?: string;
1415
keyValidation?: string;
1516
disabledArrowUpDownInputNumber?: boolean;
1617
disabledWheelMouse?: boolean;

src/hooks/useInput/useInput.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
} from 'react';
1010

1111
import { useInternalValidations } from '@/components/input/hooks';
12-
import { ERROR_EXECUTION, FormatNumber } from '@/components/input/types/input';
12+
import {
13+
ERROR_EXECUTION,
14+
FormatNumber,
15+
INTERNAL_ERROR_EXECUTION,
16+
} from '@/components/input/types/input';
1317
import { InputTypeType } from '@/components/input/types/inputType';
1418
import {
1519
checkValidFormattedNumber,
@@ -200,7 +204,11 @@ export const useInput = (props: ParamsTypeInputHook): ReturnTypeInputHook => {
200204
const valueControlled = controlValue(eventValue);
201205

202206
// check internal validations
203-
if (props.type !== InputTypeType.DATE) {
207+
if (
208+
props.type !== InputTypeType.DATE &&
209+
(props.internalErrorExecution === INTERNAL_ERROR_EXECUTION.ON_CHANGE ||
210+
props.internalErrorExecution === INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR)
211+
) {
204212
checkInternalValidations(eventValue);
205213
}
206214

@@ -226,6 +234,12 @@ export const useInput = (props: ParamsTypeInputHook): ReturnTypeInputHook => {
226234
};
227235

228236
const handleBlurInternal: FocusEventHandler<HTMLInputElement> = event => {
237+
if (
238+
props.internalErrorExecution === INTERNAL_ERROR_EXECUTION.ON_BLUR ||
239+
props.internalErrorExecution === INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR
240+
) {
241+
checkInternalValidations(event.target.value);
242+
}
229243
if (props.formatNumber) {
230244
// add thousand separator to the value
231245
event.target.value = addThousandSeparator(event.target.value, props.formatNumber);

0 commit comments

Comments
 (0)