mask input does not work with input from antd.
maybe the ref needs to be transferred somehow in a different way.
export const MaskedInput = () => (
<TextMask
mask={[/d/, /d/, /d/, /d/, /d/, /d/]}
render={(textMaskRef, props) => (
<Input
{...props}
ref={(inputRef) => {
inputRef && textMaskRef(inputRef?.input);
}}
/>
)}
placeholder={"4 numbers"}
/>
);
I tried to transfer the ref like this, but there was no effect
export const MaskedInput = React.memo(React.forwardRef((props, ref) => (
<TextMask
mask={[/d/, /d/, /d/, /d/, /d/, /d/]}
render={(textMaskRef, props) => (
<Input {...props} ref={(inputRef) => {
if (inputRef?.input) {
textMaskRef(inputRef?.input);
if (ref) {
ref.current = inputRef?.input;
}
}
}}
/>
)}
/>
)));
2
Answers
From my research, there seems to be a problem with ant input
ref
so you probably can’t use itInstead using a utility from text-mask called conformToMask
codesandbox: https://codesandbox.io/p/sandbox/text-mast-input-antd-forked-76qylt?file=%2Fsrc%2FMaskInput.jsx%3A1%2C1-21%2C1
Try this generic input masker where you pass the pattern
call it like
please validate your pattern first on https://regex101.com/