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

96
Visualizações
How to fix chakra-ui onChange trigger issue on PinInput Component

PinInput Component's onChange event doesn't working with the value in Chakra-UI so it is triggering even tough value doesn't change and that causes to move focus automatically to the next input once.

For Example: When I try set false the state of manageFocus attribute at the onChange event, I expected don't move focus automatically to the next input once a field isn't filled but it moves focus automatically to the next input once even though the field isn't filled.

In that example try to type invalid input to the Pin Input Field (you can write 6 it will set manageFocus attribute to false) and You will see manageFocus state will have setted to false after Pin Input moves focus to the next input once.

So is there a way configure onChange event or set the manageFocus attribute before focus change.

Note: The if statement is allowing only unique numbers between 1 to 5 with Regular Expression.

"^(?:([1-5])(?!.\1))$"

You can see the code down below:

import React, { useState } from "react";
import ReactDOM from "react-dom";
import {
  HStack,
  PinInput,
  PinInputField,
  ChakraProvider
} from "@chakra-ui/react";

function App() {
  const [value, setValue] = useState("");
  const [canMoveNext, setCanMoveNext] = useState(true);
  const regex = new RegExp("^(?:([1-5])(?!.*\\1))*$");

  const handleChange = (e) => {
    if (!regex.test(e)) {
      setCanMoveNext(false);
      return;
    }

    setCanMoveNext(true);
    setValue(e);
  };

  return (
    <ChakraProvider>
      <HStack>
        <PinInput
          type="number"
          manageFocus={canMoveNext}
          value={value}
          onChange={handleChange}
        >
          <PinInputField />
          <PinInputField />
          <PinInputField />
          <PinInputField />
          <PinInputField />
        </PinInput>
      </HStack>
    </ChakraProvider>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

Also you can see live at: codesandbox

about 4 years ago · Juan Pablo Isaza
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