From a52a0b7441b22ed6ce33f2814bcca2a4e470f61b Mon Sep 17 00:00:00 2001 From: Mike Turley Date: Sun, 13 Feb 2022 13:49:15 -0500 Subject: [PATCH] feat(ValidatedTextInput): add onBlur prop and refactor helpers to use options objects (#93) Allows passing an extra onBlur handler to ValidatedTextInput and ValidatedPasswordInput, and to facilitate it, refactors getFormGroupProps and getTextInputProps to take an object of options including the existing greenWhenValid and the new onBlur (to avoid piling on unnamed params) BREAKING CHANGE: Any direct calls to getTextInputProps or getFormGroupProps that were passing a boolean for greenWhenValid will now need to instead pass an options object including greenWhenValid as a property. --- .../ValidatedPasswordInput.tsx | 13 ++++- .../ValidatedTextInput/ValidatedTextInput.tsx | 57 +++++++++++-------- src/hooks/useFormState/useFormState.ts | 30 +++++++--- 3 files changed, 63 insertions(+), 37 deletions(-) diff --git a/src/components/ValidatedTextInput/ValidatedPasswordInput.tsx b/src/components/ValidatedTextInput/ValidatedPasswordInput.tsx index 5eae84f..cc381ec 100644 --- a/src/components/ValidatedTextInput/ValidatedPasswordInput.tsx +++ b/src/components/ValidatedTextInput/ValidatedPasswordInput.tsx @@ -8,12 +8,16 @@ import { TextInputProps, } from '@patternfly/react-core'; import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons'; -import { IValidatedFormField, getFormGroupProps, getTextInputProps } from '../..'; +import { IValidatedFormField, getFormGroupProps, getTextInputProps, TextFieldOptions } from '../..'; interface IValidatedPasswordInputProps extends Pick { /** A field returned from useFormField() or useFormState().fields. */ field: IValidatedFormField | IValidatedFormField; + /** Whether to show the green 'valid' style when the field has been validated. Defaults to false ('default' style) */ + greenWhenValid?: boolean; + /** Extra callback to call onBlur in addition to setting the field isTouched in state */ + onBlur?: () => void; /** Any extra props for the PatternFly FormGroup */ formGroupProps?: Partial; /** Any extra props for the PatternFly TextInput */ @@ -27,25 +31,28 @@ export const ValidatedPasswordInput: React.FunctionComponent { const [isValueVisible, toggleValueVisible] = React.useReducer((isVisible) => !isVisible, false); + const options: TextFieldOptions = { greenWhenValid, onBlur }; return ( )} + {...getFormGroupProps(field as IValidatedFormField, options)} {...formGroupProps} > )} />