-
Notifications
You must be signed in to change notification settings - Fork 418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typescript error when pass "size" prop with custom MUI Textfield #422
Comments
I have the same issue. How did you resolve? |
Hard workaround is to ignore the props type checking
|
Another workaround is to make a react function with the needed props: And then, passing it to customInput: |
Since this still has not been fixed I figured I would share the solution I came up with in a project I am currently working on. Here it is: type NumberTextFieldProps = Omit<NumberFormatPropsBase, "size"> & Omit<TextFieldProps, "value" | "defaultValue" | "ref" | "type">;
const TextFieldMiddleware = (params: TextFieldProps & { textFieldSize?: 'small' | 'medium' }) => {
//destructure params to take out textFieldSize
const { textFieldSize, ...otherParams } = params;
return <TextField {...otherParams} size={textFieldSize}/>
};
const NumberTextField = (props: NumberTextFieldProps) => {
const { size, ...otherProps } = props;
return (
<NumberFormat
customInput={TextFieldMiddleware}
//map the size prop to textFieldSize so it can be passed correctly to the TextFieldMiddleware component
textFieldSize={size}
{...otherProps}
/>
);
};
export default NumberTextField; The NumberTextField can be used in place of the NumberFormat component and will accept all props for both the NumberFormat component & TextField component, and it will map the 'size' param correctly to the TextField component. |
any updates on this issue? |
Hello!
I`m using NumberFormat + Material UI + TypeScript
When i give
customInput={TextField}
andsize={"small"}
, I got error from TypeScript:Here`s my component:
If I remove
size
prop, everything works fine andTextField
recieve all other props (label
,helperText
, etc.)The text was updated successfully, but these errors were encountered: