ListItem doesn't accept prop htmlFor (TypeScript)
See original GitHub issueThis is a Typescript error
The ListItem component accepts label for the prop component but doesn’t accept the htmlFor prop as it should
- This is a v1.x issue.
- I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
If I provide a value of label to the prop component
of the ListItem
component I should also be able to provide the prop htmlFor
So
<ListItem component="label" htmlFor="foo" />
should crate this HTML
<label for="foo />
Current Behavior
Instead I get the type error
Property 'htmlFor' does not exist on type 'IntrinsicAttributes & ListItemProps & { children?: ReactNode; }'.
Steps to Reproduce
Link: https://codesandbox.io/s/r0pr5qjnzq
Context
I try to use the label to trigger a hidden <input type="file" />
Your Environment
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:11 (9 by maintainers)
Top Results From Across the Web
ListItem doesn't accept prop htmlFor (TypeScript) · Issue #12486
This is a Typescript error. The ListItem component accepts label for the prop component but doesn't accept the htmlFor prop as it should....
Read more >Typescript + React/Redux: Property "XXX" does not exist on ...
It looks (to my relatively new React eyes) like Connect was not supplying an explicit interface to the container component, so it was...
Read more ><nav>: The Navigation Section element - MDN Web Docs
The HTML element represents a section of a page whose purpose is to provide navigation links, either within the current document or to...
Read more >Learn How To Use React With TypeScript By Building Yet ...
Let's create an interface for TodoListItem . It should accept a todo property of type Todo . Add the following code: interface Props...
Read more >How To Build a Customer List Management App with React ...
Here you've defined a React component in Typescript. In this case, the Create class component accepts props (short for “properties”) of type ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The solution to this problem is well known but not documented. @pelotom maybe we should put it into the TypeScript guide? I don’t know I have seen this question multiples times here. Or maybe we should just direct people to StackOverflow.
@pixelkritzel You need to explicitly use an intermediate component. Here is how I would do it in pure JavaScript, you can add the typing after:
@oliviertassinari as it happens I’ve been working on a better solution to this problem, basically a continuation of #11731… stay tuned!