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

Pasting into PinInput doesn't handle case where value in clipboard has whitespace or line break #5340

Closed
armanatz opened this issue Nov 28, 2023 · 1 comment
Labels
Fixed patch Completed issues that will be published with next patch (1.0.X)

Comments

@armanatz
Copy link
Contributor

armanatz commented Nov 28, 2023

What package has an issue?

@mantine/core

Describe the bug

Using the PinInput component, if a user tries to paste a value from the clipboard that has any whitespace or line breaks, the value does not get pasted into the input.

Since PinInput can be used for things like one time codes, if a user receives a code via email and accidentally copies a whitespace or line break, they won't be able to paste the code.

You can try the following codes on the Mantine docs for PinInput to reproduce the issue. Make sure you copy them exactly as shown below in order to simulate the whitespace or line breaks problem.

1234
1234

1234

What version of @mantine/* packages do you have in package.json? (Note that all @mantine/* packages must have the same version in order to work correctly)

7.1.3

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

No response

Do you know how to fix the issue

Yes

Do you want to send a pull request with a fix?

Yes

Possible fix

The bug occurs due to the regex check in the handlePaste function of PinInput returning false and thus not allowing the setValue(copyValue) to execute.

I suggest trimming the clipboard value instead of taking it as is so that the regex passes the test correctly.

The offending lines can be found here: https://github.com/mantinedev/mantine/blob/master/src/mantine-core/src/components/PinInput/PinInput.tsx#L291-L296

We could add a .trim() to the end of line 291 in the file above which will fix the issue.

@rtivital rtivital added the Fixed patch Completed issues that will be published with next patch (1.0.X) label Dec 4, 2023
@rtivital
Copy link
Member

rtivital commented Dec 7, 2023

Fixed in 7.3.1

@rtivital rtivital closed this as completed Dec 7, 2023
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