diff --git a/src/lib/components/inputs/basic/password/Password.tsx b/src/lib/components/inputs/basic/password/Password.tsx index 5e545544..beffaf51 100644 --- a/src/lib/components/inputs/basic/password/Password.tsx +++ b/src/lib/components/inputs/basic/password/Password.tsx @@ -24,7 +24,8 @@ export const Password = (props: InputProps) => { } useEffect(() => { - props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) + const { isValid, nonBlocking } = getResultantValidationResponse(validationResponse) + props.onValidate?.call(null, isValid, nonBlocking) }, [validationResponse]) return ( diff --git a/src/lib/components/inputs/basic/search/Search.tsx b/src/lib/components/inputs/basic/search/Search.tsx index da986997..de0dd1f7 100644 --- a/src/lib/components/inputs/basic/search/Search.tsx +++ b/src/lib/components/inputs/basic/search/Search.tsx @@ -21,7 +21,8 @@ export const Search = (props: InputProps) => { } useEffect(() => { - props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) + const { isValid, nonBlocking } = getResultantValidationResponse(validationResponse) + props.onValidate?.call(null, isValid, nonBlocking) }, [validationResponse]) return ( diff --git a/src/lib/components/inputs/basic/shared/types.ts b/src/lib/components/inputs/basic/shared/types.ts index 9096484d..0c178884 100644 --- a/src/lib/components/inputs/basic/shared/types.ts +++ b/src/lib/components/inputs/basic/shared/types.ts @@ -21,8 +21,7 @@ export type InputProps = { multipleCriteriaInfo?: boolean criteria?: InputValidation | InputValidation[] onChange?: ChangeEventHandler - onValidate?: (isValid: boolean) => void - onFeedback?: (validationResponse: InputCriteriaResponse | InputCriteriaResponse[]) => void + onValidate?: (isValid: boolean, nonBlocking: boolean) => void inputStyles?: SharedProps readOnly?: boolean autoComplete?: AutocompleteValues @@ -51,6 +50,7 @@ export type InputCriteriaResponse = { type: InputResponseType icon?: IconName isValid: boolean + nonBlocking: boolean } export const criteriaRule = ( @@ -82,15 +82,26 @@ export const criteriaRule = ( export const getResultantValidationResponse = ( validationResponse?: InputCriteriaResponse | InputCriteriaResponse[] -) => { +): { + isValid: boolean + nonBlocking: boolean +} => { if (!validationResponse) { - return false + return { isValid: false, nonBlocking: false } } if (Array.isArray(validationResponse)) { - const allResp = validationResponse.map((v) => v.isValid) - return allResp.includes(false) ? false : true + const allResp = validationResponse.map((v: InputCriteriaResponse) => { + const { isValid, nonBlocking } = v + return { isValid, nonBlocking } + }) + + const found = allResp.find((v) => v.isValid === false) + + if (found) { + return found + } } - return validationResponse.isValid + return { isValid: true, nonBlocking: true } } diff --git a/src/lib/components/inputs/basic/text/Text.tsx b/src/lib/components/inputs/basic/text/Text.tsx index 281b2ee6..06da24e9 100644 --- a/src/lib/components/inputs/basic/text/Text.tsx +++ b/src/lib/components/inputs/basic/text/Text.tsx @@ -16,7 +16,8 @@ export const Text = (props: InputProps) => { } useEffect(() => { - props.onValidate?.call(null, getResultantValidationResponse(validationResponse)) + const { isValid, nonBlocking } = getResultantValidationResponse(validationResponse) + props.onValidate?.call(null, isValid, nonBlocking) }, [validationResponse]) return ( diff --git a/src/lib/hooks/useInputValidation.ts b/src/lib/hooks/useInputValidation.ts index 83513f8a..86655ea1 100644 --- a/src/lib/hooks/useInputValidation.ts +++ b/src/lib/hooks/useInputValidation.ts @@ -37,9 +37,9 @@ const handleResponse = ( message = !isEmpty(validMessage) ? validMessage : '' } - if (!isValid && nonBlocking) { - type = 'warning' - } + // if (!isValid && nonBlocking) { + // type = 'warning' + // } const icon = getValidationIcon(type) @@ -47,7 +47,8 @@ const handleResponse = ( message, type: type, icon, - isValid + isValid, + nonBlocking } }