Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

151
Visualizações
After onBlur the input is not accessible

I am using onBlur to change the state of the error, to validate the value in the input component. But as the user click away from the input, it takes a few seconds until he can click back the input to change the value.

Can anyone know why this happens? Another question,how can I change the type of the event returned from onBlur so not to be 'any'?

Form.tsx

  const [errorFlag, setErrorFlag] = useState(false);
  const [plz, setPLZ] = useState<string | undefined>(undefined);

  const onBlur = (e:any) => {
    setErrorFlag(e.target.checkValidity());
    };
      return (<Fragment>
          ...
          <Input 
            onChange={setPLZ}
            name="PLZ" 
            pattern="^[0-9]{5}$"
            errorMessage="* Invalid Postal Code"
            error={plz === ''} 
            required={true}
            onBlur={onBlur}  
            style={{ flexGrow: 0, width: '100px', marginRight: '20px' }}
          />
        </Fragment>)

FormInput.tsx

export interface InputProps {
  ...
  onChange?: (value: string) => void;
  onBlur?:(event: React.ChangeEvent<HTMLInputElement>) => void;
}

export class Input extends React.Component<InputProps, {
  value: string;
}> {

  constructor(props: InputProps) {
    super(props);
    this.state = { value: '' };
  }

  private onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
    this.setState({ value: event.target.value });
    this.props.onChange?.(event.target.value);
   
  }
  private onBlur = (event: React.ChangeEvent<HTMLInputElement>) => {
    this.props.onBlur?.(event);
 }
  
  render() {

    return (
      <div key="form-name" className="formrow" style={{...this.props.style}}>
        <input 
          ... 
          onChange={this.onChange} 
          onBlur={this.onBlur}
          />
        <span id="formInput-errorspan" className="errorSpan">{this.props.errorMessage}</span>
      </div>
    );
  }
}

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I have not an idea for your first question, but you can use

<React.FocusEventHandler<HTMLInputElement | HTMLTextAreaElement> | undefined>

as type for your onBlur Event

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda