question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ListItem doesn't accept prop htmlFor (TypeScript)

See original GitHub issue

This 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 screen shot 2018-08-12 at 17 15 41

Context

I try to use the label to trigger a hidden <input type="file" />

Your Environment

Link to my current package.json and the repo itself

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:3
  • Comments:11 (9 by maintainers)

github_iconTop GitHub Comments

4reactions
oliviertassinaricommented, Aug 12, 2018

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:

const Label = props => <label htmlFor="foo" {...props} />

<ListItem component={Label} />
1reaction
pelotomcommented, Aug 13, 2018

@oliviertassinari as it happens I’ve been working on a better solution to this problem, basically a continuation of #11731… stay tuned!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found