Skip to content

Commit

Permalink
Cluster name show validation message when typing characters
Browse files Browse the repository at this point in the history
  • Loading branch information
ammont82 committed Mar 6, 2024
1 parent 8a0e737 commit fae753d
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions libs/ui-lib/lib/common/components/ui/formik/RichInputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ import {
FormGroup,
HelperTextItem,
TextInput,
HelperText as PFHelperText,
HelperText,
HelperTextItemProps,
Popover,
PopoverPosition,
InputGroup,
Button,
InputGroupItem,
FormHelperText,
HelperText,
} from '@patternfly/react-core';
import { CheckCircleIcon } from '@patternfly/react-icons/dist/js/icons/check-circle-icon';
import { CheckIcon } from '@patternfly/react-icons/dist/js/icons/check-icon';
Expand Down Expand Up @@ -58,7 +57,7 @@ export const RichValidation: React.FC<RichValidationProps> = ({
richValidationMessages,
}) => {
return (
<PFHelperText component="ul" className="rich-input__rules">
<HelperText component="ul" className="rich-input__rules">
{Object.keys(richValidationMessages).map((key) => {
const variant = getHelperTextVariant(richValidationMessages[key], value, error);
return (
Expand All @@ -67,7 +66,7 @@ export const RichValidation: React.FC<RichValidationProps> = ({
</HelperTextItem>
);
})}
</PFHelperText>
</HelperText>
);
};

Expand Down Expand Up @@ -99,6 +98,12 @@ const RichInputField: React.FC<RichInputFieldPropsProps> = React.forwardRef(
const fieldId = getFieldId(props.name, 'input', idPostfix);
const isValid = !(touched && error?.length);

React.useEffect(() => {
if (value !== '') {
setPopoverOpen(true);
}
}, [value]);

return (
<FormGroup
id={`form-control__${fieldId}`}
Expand Down Expand Up @@ -128,6 +133,7 @@ const RichInputField: React.FC<RichInputFieldPropsProps> = React.forwardRef(
shouldOpen={() => setPopoverOpen(true)}
aria-label="validation popover"
position={PopoverPosition.top}
withFocusTrap={false}
bodyContent={
<RichValidation
value={value}
Expand Down

0 comments on commit fae753d

Please sign in to comment.