Closed iamricky closed 5 years ago
hi! Sorry, don't have time to investigate Ant, but by this error it seems that HTML-element was not passed to imask plugin. You probably have to change code a little bit to correctly pass native element reference to imask mixin. Take a look as it was done for IMaskInput and try to modify it according to Ant docs.
Hey, I ended up switching to Text Mask and got it up running instantly by creating a DOM ref. Thanks for replying anyways.
As Text Mask is not maintained anymore, here a solution to have an ant design "look" input:
IMaskMixin(({ inputRef, ...props }) => (
<input className="ant-input" ref={inputRef} {...props} />
));
To get the original input element, we can use callback on the ref prop and extract the element from input
field of <Input/>
component instance:
// types.d.ts
// based on https://github.com/uNmAnNeR/imaskjs/issues/329#issuecomment-708418004
export function IMaskMixin<T, D>(
Component: React.ComponentType<{ inputRef: React.RefCallback<D> } & T>,
): React.ComponentType<T & IMaskInputProps>;
// NumberField.tsx
import React from 'react';
import { Input, InputProps } from 'antd'; // v. 4.5.14
import { IMaskMixin } from 'imask-react'
const MaskedInput = IMaskMixin<InputProps, HTMLInputElement>(({ inputRef, ...props }) => {
const extractInputRef = React.useCallback(
(inst: React.ElementRef<typeof Input>) => inputRef(inst?.input),
[inputRef],
);
return <Input ref={extractInputRef} {...props} />;
});
export const NumberField = () => <MaskedInput mask={Number} size="large" />;
I've run into an issue, while using
react-imask
's mixin w/Ant Design's Input component. Here's a simple implementation:and here are the errors I get:
Any idea what could be the cause of this issue or how I can address it?