Using text-mask with Ant design Input component
See original GitHub issueHi guys,
I have been testing this library to implement my personal project. And as you understand from the title, I want to use this component together with ant design Input component using its render attribute. However, it doesn’t work with that.
<TextMask
mask={[/[12]/, /\d/, /\d/, /\d/, "-", /[01]/, /\d/, "-", /[0-3]/, /\d/]}
placeholderChar="_"
showMask
render={(ref, props) => (
<Input
name="phone"
className="form-control"
placeholder="Hey I am Ant design Input"
required
ref={ref}
{...props}
/>
)}
/>
If I change the <Input>
tag with <input>
It shows formatted text like we expect.
My main intention to show every input component should be displayed like an ant design component.
You can make it using react-input-mask library.
Issue Analytics
- State:
- Created 5 years ago
- Comments:16
Top Results From Across the Web
Using Text Mask component with Ant design Input
I have been testing 'react-text-mask' library and I want to use this component together with ant design Input component using its render ...
Read more >Input - Ant Design
A basic widget for getting the user input is a text field. ... You can use the Input in conjunction with Tooltip component...
Read more >antd-mask-input - npm Package Health Analysis - Snyk
An Ant Design Input component for <input> masking, built on top of imask. The version 2.0.0 Requires antd >= 4.19.0 - for previous...
Read more >antd-mask-input examples - CodeSandbox
Learn how to use antd-mask-input by viewing and forking example apps that make use of antd-mask-input on CodeSandbox. React / Ant Design /...
Read more >React-text-mask NPM
Customize Rendered <input> Component. For advanced uses, you can customize the rendering of the resultant <input> via a render prop. This is entirely...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Just set de className like this: className=“ant-input”
@Stackout What
antd
version are you on?I tried implementing your solution but I could not get the masking to go through.
Also how are you implementing your form logic? Are you passing down the
form
prop from the parent or is it the one from the decoratorForm.create()(Input)
? How are you handling the field validation with that phone number input?EDIT:
After spending some time playing around and digging into how
getFieldDecorator
andInput
work; I was able to figure out something that works under the versions I have (latest as of July 2019).Here is a gist of the
PhoneNumberInput
I created: https://gist.github.com/FrenchMajesty/6758013397e065a831211879423818fdAnd it would simply be used as follow:
I designed the
PhoneNumberInput
component to work well specifically within aForm
but I’m sure it can be tweaked depending on use case.