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

Normal TextInput behaviour on undefined mask property #41

Open
jimmi-joensson opened this issue Aug 23, 2021 · 2 comments
Open

Normal TextInput behaviour on undefined mask property #41

jimmi-joensson opened this issue Aug 23, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@jimmi-joensson
Copy link
Contributor

Describe the Feature

I think it would make sense to make the MaskedTextInput component fallback to the normal TextInput behaviour when the mask property is undefined. This would mean that anything written in the input would be passed on in both text and rawText.

Possible Implementations

export const CustomInput = ({...props}: CustomInputProps) => {
  const [value, setValue] = React.useState('Hello world')

  const handleChangeText = React.useCallback((text, rawText) => {
    console.log('text:', text)
    console.log('rawText:', rawText)
    setValue(text)
  }, [])
  
  return (
      <MaskedTextInput
        mask={undefined}
        onChangeText={(text, rawText) => setValue(text)}}
        value={value}
        {...props}
      />
  )
}

// Typing "!" suffixed on "Hello world" in the input

// text: Hello world!
// rawText: Hello world!
@jimmi-joensson jimmi-joensson added the enhancement New feature or request label Aug 23, 2021
@akinncar
Copy link
Owner

I can't see a real-world usage for this and don't think that is a good option because if you need to use an input without a mask, is most recommended to use TextInput, and avoid MaskedtTextInput logic.

But of course that it can be implemented because this tends more to help the DX than to make it worse

PR's are welcome!

@jimmi-joensson
Copy link
Contributor Author

jimmi-joensson commented Aug 24, 2021

I think you're right about that MaskedTextInput should not replace TextInput completely. However I do think the behaviour as it is right know, is a bit weird. I don't see why any masking should happen if the mask prop is undefined. If masking should always happen when using the component, then I believe the mask should be a required prop, instead of an optional.

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

No branches or pull requests

2 participants