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

The caret position isn't set properly when I use the removeFormatting function to use the Persian numbers with the thousandSeparator prop #834

Open
3 of 6 tasks
hamiidrahmani opened this issue Apr 8, 2024 · 3 comments

Comments

@hamiidrahmani
Copy link

Describe the issue and the actual behavior

The caret position isn't set properly when I use the removeFormatting function to use the Persian numbers with the thousandSeparator prop, It should be fixed at the last item of input when I'm writing.

Describe the expected behavior

I think it should be considered to detect automatically where the caret position is when I'm typing.

Provide a CodeSandbox link illustrating the issue

https://codesandbox.io/p/sandbox/custom-numeral-numer-format-forked-qsy7ft?file=%2Fsrc%2FApp.js%3A12%2C31
Also, I provide a video to give a good understanding:

Screen.Recording.2024-04-09.at.1.53.18.AM.mov

Provide steps to reproduce this issue

Please check the browsers where the issue is seen

  • Chrome
  • Chrome (Android)
  • Safari (OSX)
  • Safari (iOS)
  • Firefox
  • Firefox (Android)
@hamiidrahmani
Copy link
Author

I traced back the issue, It seems that we need to modify the isCharacterSame function, because currentValue and formattedValue differ in the last character position for Persian input.

const _isCharacterSame: IsCharacterSame = (ref) => {
    ref.currentValue = persianToEnglishNum(ref.currentValue);
    return isCharacterSame!(ref);
  };

@Melancholism
Copy link

@hamiidrahmani Could you please share the complete code.

@hamiidrahmani
Copy link
Author

@hamiidrahmani Could you please share the complete code.

Only pass the function to NumberFormatBase, something like this:

const {  isCharacterSame, ...numericFormatProps } = useNumericFormat();

const _isCharacterSame: IsCharacterSame = (ref) => {
    ref.currentValue = persianToEnglishNum(ref.currentValue);
    return isCharacterSame!(ref);
  };


<ReactNumberFormatBase
      {...numericFormatProps}
      isCharacterSame={_isCharacterSame}
    />

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants