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

Using decimalSeparator with a suffix containing more than one character brakes the seperator behavior #725

Closed
2 tasks done
musbou opened this issue Jan 31, 2023 · 6 comments · Fixed by #756
Closed
2 tasks done

Comments

@musbou
Copy link

musbou commented Jan 31, 2023

Describe the issue and the actual behavior

As stated in title, when using decimalSeparator in conjunction of a suffix with more than one character, typing the default separator . (or any other separator if you have a list allowedDecimalSeparator) does not move the caret. It will leave the cursor before the dot and not after. So you'll be inputing whole numbers still, unless you use the mouse or arrow keys to navigate after the separator.

Having one character suffix fixes this issue.

Example of usage:

<NumericFormat
     value={0}
     decimalSeparator=","
     allowedDecimalSeparators={["%"]}
     decimalScale={2}
     suffix=" €"
/>

Describe the expected behavior

Inputing the decimal separate should leave the cursor after the separator.

Provide a CodeSandbox link illustrating the issue

https://codesandbox.io/s/tender-dream-914v43

Provide steps to reproduce this issue

See codesandbox.

Please check the browsers where the issue is seen

  • Chrome
  • Firefox
@musbou
Copy link
Author

musbou commented Jan 31, 2023

After some further experimenting, it turns out that the presence of more than 1 character is the issue. I update the issue.

@musbou musbou changed the title Using decimalSeparator with a suffix containing white space brakes the seperator behavior Using decimalSeparator with a suffix containing more than one character brakes the seperator behavior Jan 31, 2023
@romanopassalacqua
Copy link

I'm also facing this issue.

I did some debugging and the if in src/utils.tsx#L334 compares the inputted char (key pressed) with the formatted char. Should this if check for allowedDecimalSeparators and decimalSeparator? I think it has something to do with this if because if the key pressed is the decimalSeparator it works.

src/utils.tsx#L334

  for (let i = 0; i < curValLn; i++) {
    indexMap[i] = -1;
    for (let j = 0, jLn = formattedValueLn; j < jLn; j++) {
      // ↓
      if (curValue[i] === newFormattedValue[j] && addedIndexMap[j] !== true) {
        indexMap[i] = j;
        addedIndexMap[j] = true;
        break;
      }
    }
  }

Not sure if #673 could be related to this

@sormpe
Copy link

sormpe commented Mar 8, 2023

Hi,

I faced this issue too, and opened a PR to fix it. #743

@sormpe
Copy link

sormpe commented Mar 9, 2023

I tested v4.9.2 and it worked perfectly. Major changes in RNF v5 broke this.

s-yadav added a commit that referenced this issue May 14, 2023
The cursor position not being correct when allowed decimal separator is typed
s-yadav added a commit that referenced this issue May 14, 2023
The cursor position not being correct when allowed decimal separator is typed
@s-yadav
Copy link
Owner

s-yadav commented May 14, 2023

This is fixed on v5.2.0

@TitoSniberb
Copy link

This is partially fixed. Now the caret does move but ONLY if there are a previous value. If the first thing you do is type in the decimal separator, the caret won't move.

This is pretty common usage when dealing with < 1 values, as you directly type , or . instead of 0

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

Successfully merging a pull request may close this issue.

5 participants