Skip to content

Commit 6fe0a74

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 f134685 commit 6fe0a74

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

src/components/inputSearch/hooks/useInputSearch.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import {
1313
} from 'react';
1414

1515
import { useInternalValidations } from '@/components/input/hooks';
16-
import { InputState, InputTypeType, InternalErrorType } from '@/components/input/types';
16+
import {
17+
INTERNAL_ERROR_EXECUTION,
18+
InputState,
19+
InputTypeType,
20+
InternalErrorType,
21+
} from '@/components/input/types';
1722
import { useCustomHeightFromChildrens, useMediaDevice } from '@/hooks';
1823
import { useInput } from '@/hooks/useInput/useInput';
1924
import {
@@ -55,6 +60,7 @@ type ParamsType = {
5560
maxLength?: number;
5661
searchFilterConfig?: SearchFilterConfig;
5762
caseSensitive?: boolean;
63+
internalErrorExecution?: INTERNAL_ERROR_EXECUTION;
5864
onClick?: (event: React.MouseEvent<HTMLInputElement, MouseEvent>) => void;
5965
onIconClick?: React.MouseEventHandler<HTMLButtonElement>;
6066
executeInternalOpenOptions?: boolean;
@@ -239,6 +245,7 @@ export const useInputSearch = ({
239245

240246
// Input Basic hook
241247
const { state, inputRef, handleBlurInternal, handleFocusInternal } = useInput({
248+
internalErrorExecution: props.internalErrorExecution,
242249
ref: props.ref,
243250
disabled: props.disabled,
244251
error: props.error || internalErrors.length > 0,

src/components/inputSearch/inputSearch.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22

3-
import { InputTypeType } from '@/components/input';
3+
import { INTERNAL_ERROR_EXECUTION, InputTypeType } from '@/components/input';
44
import { STYLES_NAME } from '@/constants';
55
import { useMediaDevice, useStyles } from '@/hooks';
66
import { ErrorBoundary, FallbackComponent } from '@/provider/errorBoundary';
@@ -22,6 +22,7 @@ const InputSearchComponent = React.forwardRef(
2222
disableErrorInvalidOption = false,
2323
clearTextInputPopoverIconClick = true,
2424
highlightedOption = '',
25+
internalErrorExecution = INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR,
2526
value,
2627
disabled,
2728
error,
@@ -73,6 +74,7 @@ const InputSearchComponent = React.forwardRef(
7374
handleInputPopoverKeyDown,
7475
handleOptionsListKeyDown,
7576
} = useInputSearch({
77+
internalErrorExecution,
7678
open,
7779
type,
7880
options: optionList,
@@ -123,6 +125,7 @@ const InputSearchComponent = React.forwardRef(
123125
maxLength={maxLength}
124126
open={openOptions}
125127
optionList={optionsFiltered}
128+
regex={regex}
126129
searchText={searchText}
127130
state={state}
128131
styles={styles}

src/components/inputSearch/inputSearchStandAlone.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export const InputSearchStandAloneComponent = (
9999
(refInput as MutableRefObject<HTMLInputElement | null | undefined>)?.current,
100100
(refIcon as MutableRefObject<HTMLSpanElement | null | undefined>)?.current,
101101
]}
102+
regex={props.regex}
102103
searchText={props.searchText}
103104
state={props.state}
104105
styles={props.styles}

src/components/inputSearch/types/inputSearch.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@ import { ReactNode } from 'react';
33
import { IElementOrIcon } from '@/components/elementOrIcon';
44
import {
55
IInputStandAlone,
6+
INTERNAL_ERROR_EXECUTION,
67
InputHelpMessageType,
78
InputLabelType,
89
InputState,
910
InputStylesProps,
1011
} from '@/components/input/types';
1112
import { ListOptionsOptionType } from '@/components/listOptions';
1213
import { ILoader } from '@/components/loader/types';
14+
import { OptionSublabelType } from '@/components/option';
1315
import { IText } from '@/components/text/types';
1416
import { CustomTokenTypes, DeviceBreakpointsType } from '@/types';
1517

@@ -84,8 +86,9 @@ export interface IPopoverSearchList {
8486
hasResultTextWrittenByUser?: boolean;
8587
state: InputState;
8688
styles: InputSearchStylesProps;
87-
sublabel?: string;
89+
sublabel?: OptionSublabelType;
8890
titleActionBottomSheet?: string;
91+
regex?: string | RegExp;
8992
value?: string;
9093
caseSensitive?: boolean;
9194
// Functions
@@ -155,6 +158,7 @@ export interface IInputSearchStandAlone extends Omit<IInputStandAlone, propsToOm
155158
searchText?: string;
156159
value?: string;
157160
titleActionBottomSheet?: string;
161+
regex?: string | RegExp;
158162
// listOptions
159163
caseSensitive?: boolean;
160164
listOptionsHeight: string;
@@ -168,7 +172,7 @@ export interface IInputSearchStandAlone extends Omit<IInputStandAlone, propsToOm
168172
hasResultTextWrittenByUser?: boolean;
169173
hasHighlightedOption?: boolean;
170174
// actionBottomSheet
171-
sublabel?: string;
175+
sublabel?: OptionSublabelType;
172176
closeIcon?: IElementOrIcon;
173177
icon?: IElementOrIcon;
174178
// input popover
@@ -225,6 +229,7 @@ export interface IInputSearch<V = undefined extends string ? unknown : string>
225229
searchFilterConfig?: SearchFilterConfig;
226230
disableErrorInvalidOption?: boolean;
227231
regex?: string | RegExp;
232+
internalErrorExecution?: INTERNAL_ERROR_EXECUTION;
228233
onClick?: (event: React.MouseEvent<HTMLInputElement, MouseEvent>) => void;
229234
clearTextInputPopoverIconClick?: boolean;
230235
onChange?: (event: React.ChangeEvent<HTMLInputElement>) => void;

0 commit comments

Comments
 (0)