react-input-mask icon indicating copy to clipboard operation
react-input-mask copied to clipboard

Add noSpaceBetweenChars option

Open dbalatero opened this issue 7 years ago • 10 comments

@sanniassin Here is my first pass at this. I tried to get Mocha set up for writing fast unit tests, but I was beating my head against getting import statements to work in the Mocha tests. I didn't really want to mess with your babel-env too much, but I think it would be good to be able to easily unit test src/utils, since they tend to do some important lifting.

Closes #155

dbalatero avatar Sep 10 '18 22:09 dbalatero

@dbalatero Thank you. I'll take a close look in a few days. Sorry for the delay.

sanniassin avatar Sep 11 '18 19:09 sanniassin

@dbalatero Since the idea is to mimic the regular input behavior, there are a couple more things need to be adjusted:

  • Cursor shouldn't be allowed to move after the first empty position
  • Typing over existing character should insert the typed character before the existing one, not replace it

So these two inputs should behave almost identically. The only difference is that in the second case input value will always contain six characters with spaces in place of the empty ones.

<InputMask mask="999999" maskChar={null} />
<InputMask mask="999999" maskChar=" " noSpaceBetweenChars />

sanniassin avatar Sep 15 '18 08:09 sanniassin

Since the idea is to mimic the regular input behavior, there are a couple more things need to be adjusted

@sanniassin Sounds good, I will get to these as well.

Typing over existing character should insert the typed character before the existing one, not replace it

You know, I thought this should be the behavior also, but I thought I saw other examples of the character replacing what was there. Weird, I'll try to repro it and see if that is still an issue, or maybe I had some code in there that was messing everything up.

dbalatero avatar Sep 16 '18 15:09 dbalatero

@sanniassin

Cursor shouldn't be allowed to move after the first empty position

Addressed in db12076

Typing over existing character should insert the typed character before the existing one, not replace it

Before I do anything on this, I wanted to check in first. I'm seeing this very same behavior on master, which implies to me that we might want to open a separate PR for this issue and get this one closed out? It doesn't seem like the changes I'm making here are creating the issue, since master is exhibiting the same behavior. Can you maybe double-check this for me, as maybe I'm having build caching issues between branches?

Thanks!

dbalatero avatar Oct 10 '18 17:10 dbalatero

Before I do anything on this, I wanted to check in first. I'm seeing this very same behavior on master, which implies to me that we might want to open a separate PR for this issue and get this one closed out?

Sorry, I don't get it. There are two behaviors in master. The first one replaces existing characters and it's intended for cases when maskChar isn't empty or input is filled and there is no free space left. The second one inserts new characters and keeps the existing ones. It's intended for cases with empty maskChar when input has some free space.

I propose to use the second one for noSpaceBetweenChars.

Is there something wrong with this mechanics?

sanniassin avatar Oct 14 '18 09:10 sanniassin

Is there something wrong with this mechanics?

Not at all, I think it just wasn't clear to me that there were two behaviors. Now that I know, I'll go with the second one, thanks!

I'll address these PR comments as well!

dbalatero avatar Oct 15 '18 18:10 dbalatero

@dbalatero Do you have any updates on this? I have come across a similar issue using this library and it would be great to have this an option in react-input-mask.

dreamthink avatar Oct 30 '19 22:10 dreamthink

@dreamthink hey sorry to say I've abandoned this work as it got de-prioritized at work and we just ended up living with it. I probably won't pick this back up at this point so if @sanniassin wants to close it that's fine with me.

dbalatero avatar Oct 30 '19 23:10 dbalatero

@dreamthink hey sorry to say I've abandoned this work as it got de-prioritized at work and we just ended up living with it. I probably won't pick this back up at this point so if @sanniassin wants to close it that's fine with me.

@dbalatero Is there a follow up on this?

mitchied avatar Apr 20 '20 19:04 mitchied

Nope, sorry. I can't work on this; I don't use the library anymore and I won't be able to find any time to do it. Best of luck - if you want to use this PR as a starting point please do…

dbalatero avatar Apr 20 '20 19:04 dbalatero