renato-bohler / redux-form-input-masks

Input masking with redux-form made easy
https://bohler.dev/redux-form-input-masks/
MIT License
138 stars 10 forks source link

Placeholder appears for guide:false in createTextMask #69

Closed varunthefalcon closed 5 years ago

varunthefalcon commented 5 years ago

What are you reporting?

What is the current behavior?

The prop guide: false should remove the pattern place holder in the field when no input is present. But wierd place holder ' ( ' appears for this pattern: '(999) 999-9999'. Changing the pattern to '[999] 999-9999' gives desired empty place holder.

What is the expected behavior?

The prop guide: false should completely remove any pattern place holder in the field when no input is present.

Sandbox Link

https://codesandbox.io/s/749586m240

What's your environment?

redux-form-input-masks : 2.0.1 ReactJS : 16.6.3 NodeJS : 10.15.0 NPM : 6.4.1 Browser : Chrome 72.0.3626.121 (64-bit) OS : Ubuntu 18.04

Other information

renato-bohler commented 5 years ago

Hello!

So, when the guide is set to false, the value will be displayed only to the last informed character. In this case, if input is empty and there's some characters before any inputtable char in the pattern, these leading characters will be shown. That is the expected behaviour. For example:

createTextMask({ pattern: '(999)', guide: false }); // will format to `(` if the value is empty
createTextMask({ pattern: '[999]', guide: false }); // will format to `[` if the value is empty

If you want that in this case nothing is shown, you can set the allowEmpty option to true:

createTextMask({ pattern: '(999)', guide: false, allowEmpty: true }); // will format to `` if the value is empty
createTextMask({ pattern: '[999]', guide: false, allowEmpty: true }); // will format to `` if the value is empty

Also, I couldn't reproduce this behaviour by forking your codesandbox (here), using the our latest version (2.0.1). For instance, these masks:

const phoneMaskParenthesis = createTextMask({
  pattern: "(999) 999-9999",
  guide: false,
  allowEmpty: true
});

const phoneMaskBrackets = createTextMask({
  pattern: "[999] 999-9999",
  guide: false,
  allowEmpty: true
});

Behave like this (which, again, is the expected behaviour):

Peek 2019-03-20 19-16

varunthefalcon commented 5 years ago

Thank you for your response.