5.5.0 • Published 3 years ago

react-text-mask v5.5.0

Weekly downloads
345,675
License
Unlicense
Repository
github
Last release
3 years ago

React Input Mask

Getting started

First, install it.

npm i react-text-mask --save

Then, require it and use it.

import React from 'react'
import MaskedInput from 'react-text-mask'

export default () => (
  <div>
    <MaskedInput
      mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
    />
  </div>
)

<MaskedInput/> is fully compatible with <input/> element. So, you can pass it CSS classes, a placeholder attribute, or even an onBlur handler.

For example, the following works:

<MaskedInput
  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.

Example

To see an example of the code running, follow these steps:

  1. Clone the repo, git clone [email protected]:text-mask/text-mask.git
  2. cd text-mask
  3. npm install
  4. npm run react:dev
  5. Open http://localhost:3000

The code of the example is in react/example.

Customize Rendered <input> Component

For advanced uses, you can customize the rendering of the resultant <input> via a render prop. This is entirely optional, if no render prop is passed, a normal <input> is rendered.

For example, to use with styled-components, which requires an innerRef:

<MaskedInput
  mask={['(', /[1-9]/, /\d/, /\d/, ')', ' ', /\d/, /\d/, /\d/, '-', /\d/, /\d/, /\d/, /\d/]}
  placeholder="Enter a phone number"
  id="my-input-id"
  render={(ref, props) => (
    <MyStyledInput innerRef={ref} {...props} />
  )}
/>

const MyStyledInput = styled.input`
  background: papayawhip;
`;

Contributing

We would love some contributions! Check out this document to get started.

cfw-ui-components@axondev/date-range-picker@delijn/coretarnet-jumbo-reacttest-repo-practicesebrae-react-scripts@njradford/libszozengo-reactemotion-reproduce-external-libreact-paytm-createdfrontend-application@acorns/web-componentstest-acttsage.br.hypercube.web.componentsreact-interactive-payment-form@andreschort/react-datatable@flmc/lite-rendererdynamic-grid-avanade@catho-private/catho-componentsabdt-reactenotarylog-clientwocofdy2-sales-funnel@identance/sdk@republicfinance/ui-component-librarycaec-admin-webcommon-xu@ugikie/component-library@ugikie/ss-component-library@ugikie/inputsalphakit-uiclickwrap-docusignesignature-docusignyapayseek-asia-style-guideeco-libjpa-react-components@doran/react@doggoapp/doggo-ts-admin@jibadano/components@jibadano/form@avangard-ui/coresssiiixxx@everything-registry/sub-chunk-2617@solussaude/core@solussaude/reactjs-ui-corereact-lib-ui-test-55@nstseek/react-formstabeo-componentstaco-labs-uitarnet-uita-material-ui-pickerssynapsefi-chatbot-uitabler-react-uitabler-react-blackstormterampilalphatest-acttest-npm-kapustinwocomweb-ui-depswelltrax-ui-componentsxbrain-react-masksxm-uisalvato-ui-appsuper-fancy-test-packagestoriesxxxixxxstash-uitest-react-jalali-datepickerteste_lib_easy_3teste_lib_easy_4teste-joaoteste-lib-reacttext-mask-atlaskittheia-web-dsthe-fit-b2btetra-kitv.koriaginutrip-uivolo-tabler-reactjman-react-componentsjs-mui-formikjogogo-componentsjk-ui-corekedge-uijumbo-reactimpro-kitic-snacksinfotrack-mituigsaasgsi-uihornshh-cloudhltc-webapi-client-shared-componentshcm-publicintl-react-datatableintl-react-themelibrary-npmlogistics-cardinal-uimammoth-uimaterial-ui-pickers-db
5.5.0

3 years ago

5.4.3

7 years ago

5.4.2

8 years ago

5.4.1

8 years ago

5.4.0

8 years ago

5.3.2

8 years ago

5.3.1

8 years ago

5.3.0

8 years ago

5.2.1

8 years ago

5.2.0

8 years ago

5.1.0

8 years ago

5.0.2

9 years ago

5.0.1

9 years ago

5.0.0

9 years ago

4.1.0

9 years ago

4.0.0

9 years ago

3.0.0

9 years ago

2.3.1

9 years ago

2.3.0

9 years ago

2.2.1

9 years ago

2.2.0

9 years ago

2.1.0

9 years ago

2.0.0

9 years ago

1.0.0

9 years ago

0.19.0

9 years ago

0.18.3

9 years ago

0.18.2

9 years ago

0.18.1

9 years ago

0.18.0

9 years ago

0.17.5

9 years ago

0.17.4

9 years ago

0.17.3

9 years ago

0.17.2

9 years ago

0.17.1

9 years ago

0.17.0

9 years ago

0.16.0

9 years ago

0.15.1

9 years ago

0.15.0

9 years ago

0.14.1

9 years ago

0.14.0

9 years ago

0.13.0

9 years ago

0.12.0

10 years ago

0.11.1

10 years ago

0.11.0

10 years ago

0.10.0

10 years ago

0.9.0

10 years ago

0.8.3

10 years ago

0.8.2

10 years ago

0.0.1

10 years ago