material-tailwind: Property 'placeholder' is missing in type... for some 'non-form' components?
hi folks, I’m currently having a weird issue with the material-tailwind library, I tried to use the Sticky NavBar, and I got the following weird error:
Property 'placeholder' is missing in type '{ children: Element[]; className: string; }' but required in type 'Pick<NavbarProps, "children" | "className" | "color" | "translate" | "slot" | "style" | "title" | "onClick" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | ... 249 more ... | "blurred">'.ts(2741)
(alias) const Navbar: React.ForwardRefExoticComponent<Pick<NavbarProps, "children" | "className" | "color" | "translate" | "slot" | "style" | "title" | "onClick" | "key" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | ... 249 more ... | "blurred"> & React.RefAttributes<...>>
btw, this happen with the Button, Typography, Navbar and IconButton (idk if other components will have the issue) I’ve used this library in another project and that error never appeared, I have more dependencies but this are the ones I believe may be related:
"dependencies": {
"@heroicons/react": "^2.0.18",
"@material-tailwind/react": "^2.1.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.20.1",
"vite-tsconfig-paths": "^4.2.2"
},
"devDependencies": {
"@types/node": "^20.10.4",
"@types/react-dom": "^18.2.17",
"@types/react-router-dom": "^5.3.3",
"@types/react": "^18.2.43",
"@vitejs/plugin-react": "^4.2.1",
"autoprefixer": "^10.4.16",
"postcss": "^8.4.32",
"sass": "^1.69.5",
"tailwind-scrollbar": "^3.0.5",
"tailwindcss": "^3.3.3",
"ts-jest": "^29.1.1",
"typescript": "^5.3.3",
"vite": "^5.0.7"
},
here is an image of my code:
let me know if you need more info to figure it out, btw I get rid of the error by simply adding placeholder="" to all the components with the error, but checking the documentation the prop placeholder doesn’t exists for those components
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 37
- Comments: 54
Commits related to this issue
- chore(dependency): set @types/react to 18.2.46 to solve material tailwind typing issue. See https://github.com/creativetimofficial/material-tailwind/issues/528 — committed to dopey2/next-js-ssg-hybrid-routing by dopey2 3 years ago
- Update package.json Confirm https://github.com/creativetimofficial/material-tailwind/issues/528 ix it — committed to NPJigaK/twitch-follower-checker by NPJigaK 3 years ago
- fix: pin to last working version fo react/types Looks like there's a bug with recent version of react/types, that causes valid Typescript to fail with some React components. This was failing builds w... — committed to nuonco/installer by jordan-acosta 2 years ago
- fix: pin to last working version of react/types Looks like there's a bug with recent version of react/types, that causes valid Typescript to fail with some React components. This was failing builds w... — committed to nuonco/installer by jordan-acosta 2 years ago
- fix: pin to last working version of react/types Looks like there's a bug with recent version of @types/react, that causes valid Typescript to fail with some React components. This was failing builds ... — committed to nuonco/installer by jordan-acosta 2 years ago
- fix: pin to last working version of react/types Looks like there's a bug with recent version of @types/react, that causes valid Typescript to fail with some React components. This was failing builds ... — committed to nuonco/installer by jordan-acosta 2 years ago
- feat: Ja/display input groups (#27) * feat: render input groups Render input groups as form fieldsets. Doesn't look great, though. Going to take a pass at a better UX. * feat: add Accordion co... — committed to nuonco/installer by jordan-acosta 2 years ago
- fix(material-tailwind): version types issue https://github.com/creativetimofficial/material-tailwind/issues/528 https://github.com/creativetimofficial/material-tailwind/issues/427 — committed to Muhammed-Rahif/The-Movieflix by Muhammed-Rahif 2 years ago
- fix(material-tailwind): version types issue https://github.com/creativetimofficial/material-tailwind/issues/528 https://github.com/creativetimofficial/material-tailwind/issues/427 — committed to Muhammed-Rahif/The-Movieflix by Muhammed-Rahif 2 years ago
- completed Home page (#9) * feat(home): completed Home page * Genres list (#10) * profile-page * GenresList Complete * rework GenresList * fix(home): genre list --------- Co-autho... — committed to Muhammed-Rahif/The-Movieflix by Irfan-Ahammed 2 years ago
- fix: temporary fix for types/react My old solution of pinning types/react to 18.2.19 isn't the best. Better to update to the new version, and use a patch of code to fix the broken parts. For referen... — committed to BobDotCom/oprf-rank-viewer by BobDotCom 2 years ago
- fix: temporary fix for types/react My old solution of pinning types/react to 18.2.19 isn't the best. Better to update to the new version, and use a patch of code to fix the broken parts. For referen... — committed to BobDotCom/oprf-rank-viewer by BobDotCom 2 years ago
- build(deps): update to next.js 15 with codemod (#80) * build(deps): update to next.js 15 with codemod * chore: reconfigure eslint * fix: fix eslint issues * fix: temporary fix for types/reac... — committed to BobDotCom/oprf-rank-viewer by BobDotCom 2 years ago
- downgrade @types/react https://github.com/creativetimofficial/material-tailwind/issues/528#issuecomment-1856348865 — committed to SEG4900-Capstone-Group-T88/AdSpot-Client by matthewsia98 2 years ago
- material-tailwind由来の型エラーをignoreする。See https://github.com/creativetimofficial/material-tailwind/issues/528 — committed to ide-an/nijigta-livers-map by ide-an 2 years ago
This is a bug, introduced in
@types/reactv18.2.20. It is tracked by issue #427, and a temporary workaround is to downgrade to@types/reactv18.2.19. (Some comments mention typescript and react need to be updated to latest as well)The “placeholder” issue is likely related. It was introduced in
@types/reactv18.2.43, so downgrading to@types/reactv18.2.42 will work as a temporary workaround.TL;DR: Until this is fixed, your best bet is to downgrade
@types/reactto v18.2.19.Hope this helps 😃
I downgraded
@types/reactto 18.2.42 and locked to this version.Now, all things are working. Thanks, Bob! ❤️
I apologize for my clear words. But this is all “Kindergarten”. If the tool provider does not provide a viable solution for an obvious bug over months nor communicates a future plan/timeline, just move away, as we did. Never do serious development with non-professional hobby tools.
You don’t have to downgrade
@types/reactversions. Just create a filematerial-tailwind.d.tsin the root of your project and add the code thereBut there is no trust in this library
I did the following to fix the bug of material-tailwind. So I run npm i @types/react@18.2.42 in my terminal.
@rafaelvieiras You are right
"@types/react": "18.2.42"is the last working version. It seems the problem was introduced when this was merged https://github.com/DefinitelyTyped/DefinitelyTyped/pull/67170Not sure how to address this, except pinning the version of @types/react.
Thx!
It’s also in
<Card />and possibly elsewhere.@don-esteban this not related to VC. 😞
Try to run
npm build(here I use pnpm), you seeProperty 'placeholder' is missing in type....This bug is happening with
Button,Typography,CardBody,CardHeaderandCard~all~ components.I made some regression tests, and on
TypographyI tried to back to 2.0.8-react version and on this version the bug no happening.But, on 2.1.0-react version, the bug came back to
Typographycomponent, maybe is related to this commit.It’s my first time on
material-tailwindand I don’t know if this is a bug or a feature. 😄Same problem on all Typography, List, Accordion etc
Confirm
@types/react@18.2.42fix it with@material-tailwind/react": "2.1.8"I was using
@material-tailwind/react": "2.1.8""@types/react": "18.2.45",Type problem was with Button component and some others
"@material-tailwind/react": "^2.1.9","next": "^14.2.0-canary.61","@types/react": "18.2.19","@types/react-dom": "18.2.25",works for me!For Next.js 15.1.6 this solved with
I don’t think anyone needs to downgrade
@types/reactor override individual component type definitions. The source of the issue is the change to theHTMLAttributesdefinition in@types/react. To keep the latest version of@types/reactand avoid overriding many components, just do this instead:@types/react@18.2.42worked for me too but make sure your it doesn’t have^at beginning. In other words, it should NOT be like this:For me running
npm i @types/react@18.2.42fixed the issue. Thanks to @Symoh-42 and @bryanlundberg for the suggestions.I had to go down to 18.2.19 to fix this. 18.2.42 didnt solve it.
// package.json
@M34R7 thx your reply. you gave me a great answer… thank you 👍
Meantime, we moved away, even for prototyping, to daisyUI. It is not material, but flexible, stable, feature rich and important too, it has a responsive and friendly contributer and user community. And have a look at open issues. daisyUI has significant more users but few open issues.
The concept is different. It doese not exposes React components. It exposes just new Tailwind untilities, doing the job. So, you do not learn new components. You learn new utility classes.
is this not solved yet?
this solve my problem
If it’s not a feature, it’ a bug.
Strange enough, installing back
npm install @material-tailwind/react@2.1.5did not help. The issue/feature persist.I did today an update of VC on Mac too. Could it be related to the VisualCode update? I’m not fluent in VC and don’t know how to downgrade to test.
By the way. I had and still have a similar issue with the Input component. It requires
crossOrigin={undefined}attribute. Without, I get a similar error message. Could not find docs about this attribute.So, if your project is still in the beginning and small, one could temporary work around with adding
placeholder={undefined}.Hello, This problem is also using Next 15 and React 19 (using v2.1.10) Any permanent solution ?
Thanks
I encountered the same issue where @types/react version 18.2.42 caused compatibility problems with certain components, especially Input.
To fix this, I downgraded to version 18.2.19, which resolved the issue for now. However, this is more of a temporary solution, and the root cause should be investigated for a proper fix.
// package.json
“devDependencies”: { … “@material-tailwind/react”: “^2.1.10”, “@types/react”: “18.2.19” … }
Type ‘{ children: Element[]; }’ is missing the following properties from type ‘Pick<CarouselProps, “children” | “className” | “color” | “transition” | “translate” | “slot” | “style” | “title” | “onChange” | “loop” | “onClick” | “key” | “defaultChecked” | … 252 more … | “slideRef”>’: placeholder, onPointerEnterCapture, onPointerLeaveCapturets(2739) (alias) const Carousel: React.ForwardRefExoticComponent<Pick<CarouselProps, “children” | “className” | “color” | “transition” | “translate” | “slot” | “style” | “title” | “onChange” | “loop” | “onClick” | “key” | … 253 more … | “slideRef”> & React.RefAttributes<…>> import Carousel
I also had the same error. I was using material-tailwind library with next.js 14.
<Carousel placeholder={undefined} onPointerEnterCapture={undefined} onPointerLeaveCapture={undefined}
I added this attribute now it’s not showing any typescript error.
I was already using daisyUI in my project. I wanted to speed up development by switching to Material Tailwind. But, I’ll stick to daisyUI moving forward. Yes, it’s not the same but stable and flexible. Also easy to pick up IMO.
I can confirm that this works
I had could solve my problem changing version like Bob mentions, some like this:
npm i @material-tailwind/react@2.1.0I’m using Next.js 15 with React 19, and I’m not sure if this hack will work for that. But this one worked for me
npm i @material-tailwind/react@betaI encountered the same issue when I tried using @vitejs/plugin-react-swc. If you replace it with @vitejs/plugin-react, the issue will go away. However, considering this issue, as well as the type problems and the slow response from the developer, it seems that using @material-tailwind/react right now is not the best idea.
I configured it as below. but, still not working… is wrong…? plz help me…
node v20.11.0
“dependencies”: { “@material-tailwind/react”: “^2.1.10”, “react”: “^18.3.1”, “react-dom”: “^18.3.1” }, “devDependencies”: { “@eslint/js”: “^9.9.0”, “@types/react”: “^18.3.3”, “@types/react-dom”: “^18.3.0”, “@vitejs/plugin-react”: “^4.3.1”, “autoprefixer”: “^10.4.20”, “eslint”: “^9.9.0”, “eslint-plugin-react-hooks”: “^5.1.0-rc.0”, “eslint-plugin-react-refresh”: “^0.4.9”, “globals”: “^15.9.0”, “postcss”: “^8.4.45”, “tailwindcss”: “^3.4.10”, “typescript”: “^5.5.3”, “typescript-eslint”: “^8.0.1”, “vite”: “^5.4.1” }
in vite-env.d.ts file
/// <reference types="vite/client" /> declare module “react” { interface HTMLAttributes { placeholder?: string; onPointerEnterCapture?: React.PointerEventHandler; onPointerLeaveCapture?: React.PointerEventHandler; } }
fixed ! thanks
Usually just put it in the root directory, since another .d.ts file - next-env.d.ts is also there.
create a file inside the src folder called
react-app-env.d.ts. tried it and the error was gone but I’m still checking if everything works.I’m also new in react tailwind so feel free to correct me.
Went through all the proposed “solutions” and nothing worked. Tinkering with my package versions doesn’t seem okay, especially in the long run. If you still have issues with the library, just look elsewhere as @don-esteban said.
FYI - This issue has already been tracked here.
I prefer not to downgrade a package version, as I understand it varies from developer to developer. Instead, we can explore manipulating type definitions.
I am using VSCode for the demo; feel free to use the IDE you prefer.
Now, you will see an error about the missing ‘prop placeholder’ if you are using TypeScript or a linter
Place your mouse on a button element where you see a reddish line; simply hover over the button.
Now, press the CTRL key and click the mouse after hovering over the button. Simply press
CTRL + CLICKNow you can see the path in the header of a popup. In my case, it is ‘C:\Users\username\OneDrive\Documents\code\solution\node_modules@material-tailwind\react\components\Button’. Click on that path.
If you see something like the image above, congratulations, we have landed on the correct page
Now, add a placeholder prop as an optional prop using the
'?'symbol in TypeScript.One drawback of this approach is that you need to follow this process for each component, such as Card, Typography, etc.
It’s quite a lengthy process, but I hope it proves helpful.
I didn’t have the time to figure out the root problem and fix what was causing it, so I resorted to the nonsense solution below.
Nonsense solution
Set your app to run react 17 if your other dependencies allows react 17. If not then kindly step away. I ended up running bootstrap for my project. To much of a hassle to fix my dependencies for v17.