<commit_before>import React, { useState } from 'react';
import { TextInput, FormGroup, TextInputProps } from '@patternfly/react-core';
import { useAnalytics } from '../../analytics';

interface ExtendedTextInputProps extends TextInputProps {
  id: string;
  helperTextInvalid: string;
}

export function ExtendedTextInput(props: ExtendedTextInputProps) {
  const [isDirty, setIsDirty] = useState(false);
  const { onChange, isValid, helperTextInvalid, label, ...rest } = props;
  const analytics = useAnalytics();
  return (
    <FormGroup
      fieldId={props.id}
      label={label}
      isValid={isValid || !isDirty}
      helperTextInvalid={helperTextInvalid}
    >
      <TextInput
        onChange={(value, event) => {
          if(!isDirty) {
            analytics.event('Input', 'Customized-Value', props.id);
          }
          setIsDirty(true);
          if (onChange) {
            onChange(value, event);
          }
        }}
        isValid={isValid || !isDirty}
        {...rest as any}
      />
    </FormGroup>
  );
}<commit_msg>fix: ExtendedTextInput can be invalid when untouched (#1333)<commit_after>import React, { useState } from 'react';
import { TextInput, FormGroup, TextInputProps } from '@patternfly/react-core';
import { useAnalytics } from '../../analytics';

interface ExtendedTextInputProps extends TextInputProps {
  id: string;
  helperTextInvalid: string;
}

export function ExtendedTextInput(props: ExtendedTextInputProps) {
  const [isDirty, setIsDirty] = useState(false);
  const { onChange, isValid, helperTextInvalid, label, ...rest } = props;
  const analytics = useAnalytics();
  const valid = (!isDirty && !props.value) || isValid 
  return (
    <FormGroup
      fieldId={props.id}
      label={label}
      isValid={valid}
      helperTextInvalid={helperTextInvalid}
    >
      <TextInput
        onChange={(value, event) => {
          if(!isDirty) {
            analytics.event('Input', 'Customized-Value', props.id);
          }
          setIsDirty(true);
          if (onChange) {
            onChange(value, event);
          }
        }}
        isValid={valid}
        {...rest as any}
      />
    </FormGroup>
  );
}
{'fraction_non_alphanumeric': 0.13143382352941177, 'fraction_numerical': 0.001838235294117647, 'mean_word_length': 2.740549828178694, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2651846', 'n_tokens_mistral': 643, 'n_tokens_neox': 643, 'n_words': 142}