React-IMask example does not work - forwardRef error
See original GitHub issueDuplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
The example documented here https://mui.com/components/text-fields/#integration-with-3rd-party-input-libraries with react-imask does not work, there is an error on line 25 “inputRef={ref}”:
Type ‘ForwardedRef<HTMLElement>’ is not assignable to type ‘ForwardedRef<HTMLElement> & (((el: MaskedElement) => void) | undefined)’. Type ‘null’ is not assignable to type ‘ForwardedRef<HTMLElement> & (((el: MaskedElement) => void) | undefined)’.ts(2322)
It looks like the ref is being passed incorrectly. I am using react-imask 6.2.2, react 17.0.2 and the latest MUI packages
Expected behavior 🤔
Component should work without error after being copy and pasted from the example doc
Steps to reproduce 🕹
Steps:
- Copy and paste code
- Run it
- Above error appears
Context 🔦
I am trying to integrate text mask into a MUI Text Field. I did this successfully in MUI v4 using react-text-mask but the new imask example does not seem to be working.
Your environment 🌎
`npx @mui/envinfo`
System:
OS: Windows 10 10.0.19042
CPU: (8) x64 Intel(R) Core(TM) i7-8565U CPU @ 1.80GHz
Memory: 2.83 GB / 15.81 GB
Binaries:
Node: 17.3.0 - C:\Program Files\nodejs\node.EXE
npm: 8.3.2 - C:\Program Files\nodejs\npm.CMD
Managers:
pip3: 21.3.1 - C:\Python38\Scripts\pip3.EXE
Utilities:
Git: 2.27.0. - /mingw64/bin/git
SDKs:
Windows SDK:
AllowAllTrustedApps: Disabled
Versions: 10.0.17763.0
IDEs:
Android Studio: Version 2020.3.0.0 AI-203.7717.56.2031.7935034
VSCode: 1.63.2 - C:\Users\danie\AppData\Local\Programs\Microsoft VS Code\bin\code.CMD
Languages:
Bash: 4.4.23 - C:\Program Files\Git\usr\bin\bash.EXE
Perl: 5.30.2 - C:\Program Files\Git\usr\bin\perl.EXE
Python: 3.8.2 - /c/Python38/python
Databases:
MongoDB: 4.2.6 - C:\Program Files\MongoDB\Server\4.2\bin\mongo.EXE
Browsers:
Chrome: 97.0.4692.99
Edge: Spartan (44.19041.1266.0), Chromium (97.0.1072.62)
Internet Explorer: 11.0.19041.1202
tsconfig
{
"compilerOptions": {
"baseUrl": "src",
"outDir": "./dist/",
"noImplicitAny": true,
"module": "esnext",
"target": "es5",
"moduleResolution": "node",
"jsx": "react",
"allowJs": true,
"strict": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"resolveJsonModule": true,
"typeRoots" : ["node_modules/@types", "src/types"]
},
"include": ["src"]
}
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6 (1 by maintainers)
Top GitHub Comments
Here is a CodeSandbox, see also.
I’m currently using the following workaround:
Looks like a problem of the typing of
inputRef
when combined withforwardRef
– therefore only the docs seem to provide a broken example. Parts of the MUI library are probably not involved in the problem and updating@mui/material
did nothing for me.I’m trying to use Formik, MUI and IMask together.
But a loop happens when performing the onChange.
I couldn’t find the error in my code: