The react-text-mask library
npm install @exodus/react-text-maskBased on text-mask
Archived fork repo (use for history)
First, install it.
``bash`
yarn add @exodus/react-text-mask
Then, require it and use it.
`js
import React from 'react'
import MaskedInput from 'react-text-mask'
export default () => (
is fully compatible with element. So, you can
pass it CSS classes, a placeholder attribute, or even an onBlur handler.For example, the following works:
`js
mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
className="form-control"
placeholder="Enter a phone number"
guide={false}
id="my-input-id"
onBlur={() => {}}
onChange={() => {}}
/>
`Documentation
For more information about the
props that you can pass to the component, see
the documentation here.Customize Rendered
ComponentFor advanced uses, you can customize the rendering of the resultant
via a render prop.
This is entirely optional, if no render prop is passed, a normal is rendered.For example, to use with styled-components,
which requires an innerRef:
`js
; mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
placeholder="Enter a phone number"
id="my-input-id"
render={(ref, props) => }
/>const MyStyledInput = styled.input
``