Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PinInput onComplete handler is called repeatedly #5774

Closed
1 of 2 tasks
mawallace opened this issue Feb 15, 2024 · 2 comments
Closed
1 of 2 tasks

PinInput onComplete handler is called repeatedly #5774

mawallace opened this issue Feb 15, 2024 · 2 comments
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@mawallace
Copy link

mawallace commented Feb 15, 2024

Dependencies check up

  • I have verified that I use latest version of all @mantine/* packages

What version of @mantine/* packages do you have in package.json?

7.5.2

What package has an issue?

@mantine/core

What framework do you use?

Remix

In which browsers you can reproduce the issue?

Safari

Describe the bug

The onComplete handler for PinInput is called repeatedly when the handler changes some state.

For example, the following calls onComplete repeatedly, causing the counter to increase uncontrollably.

function Demo() {
  const [counter, setCounter] = useState(0);

  function handleComplete() {
    console.log('complete');
    setCounter(counter + 1);
  }

  return (
    <MantineProvider>
      <PinInput onComplete={handleComplete} />
      <Text>{counter}</Text>
    </MantineProvider>
  );
}

I would expect for the onComplete handler to only be called

  1. When the input changes, if the value is complete
  2. [Optionally] When the component initially loads, if the value is complete

Note that changing state seems necessary to reproduce this, and the following does not call onComplete repeatedly.

function Demo() {
  function handleComplete() {
    console.log('complete');
  }

  return (
    <MantineProvider>
      <PinInput onComplete={handleComplete} />
    </MantineProvider>
  );
}

For context, in my use case, when the input is complete, I want to proceed with my authentication flow, and as a part of that I set some loading state to true (to trigger some visual feedback). My onComplete handler runs many times, causing issues with the auth flow.

I am currently working around this using a solution like the following, but ideally the onComplete behavior would match:

function Demo() {
  const length = 4;
  const [counter, setCounter] = useState(0);

  function handleChange(value: string) {
    if (value.length === length) {
      console.log('complete');
      setCounter(counter + 1);
    }
  }

  return (
    <MantineProvider>
      <PinInput length={length} onChange={(value) => handleChange(value)} />
      <Text>{counter}</Text>
    </MantineProvider>
  );
}

If possible, include a link to a codesandbox with a minimal reproduction

No response

Possible fix

No response

Self-service

  • I would be willing to implement a fix for this issue
@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Feb 16, 2024
@rtivital
Copy link
Member

Fixed in 7.5.3

@mawallace
Copy link
Author

Just verified that the new release works for my use case. Thanks for the quick response/fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)
Projects
None yet
Development

No branches or pull requests

2 participants