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.

[Select] Prop component + value breaks compilation for MenuItem

See original GitHub issue

Combination of both prop component + prop value seems incompatible.

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

value, a valid prop for MenuItem (inherit from li native element) seems to break compilation, if provided along with component prop. No matter if component is a native HTML element, a custom component or MUI component.

Expected Behavior 🤔

You can use both props w/o typescript compilation errors.

Steps to Reproduce 🕹

As you can see in the demo, every combination should be acceptable. As you can see in the second case, component="Typography" lets you use any Typography prop along with MenuItem props. You can comment line 18 to check this out. But when it comes to value, Typescript complains for line 15

Property 'component' does not exist on type 'IntrinsicAttributes & { action?: Ref<ButtonBaseActions>; buttonRef?: Ref<unknown>; centerRipple?: boolean; disabled?: boolean; disableRipple?: boolean; ... 4 more ...; TouchRippleProps?: Partial<...>; } & { ...; } & { ...; } & CommonProps<...> & Pick<...>'

I’ve check out how MenuItem is basically a ListItem with aditional props, and the problem persists as well using this component. Probably is something with OverridableComponent interface or BaseButton, im not sure.

Context 🔦

This “value” prop, not only an acceptable prop for native element, but it is indirectly being supported as MUI documentation for Select allows you to use MenuItem as children, but I couldn’t find a demo with, also, a prop component.

Your Environment 🌎

Tech Version
Material-UI v4.10.0 (latest)
React v16.13.1
Browser 83.0.4103.61
TypeScript 3.9.3

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
miguelCTcommented, May 28, 2020

I’m not sure if what @eps1lon mentions is exactly the reason. As @ImADrafter says, it seems more a Typescript compile error than an implementation bug per se. In the JS version of the same code, there is not even an execution error or warning.

Basically, I’ve followed the Material-UI docs and examples to use the “component” prop in Typescript with the MenuItem + Link (react-router), and the result is that same compile error. So, I guess this could be one of the cases stated in the TS guide, where it says:

Not every component fully supports any component type you pass in. If you encounter a component that rejects its component props in TypeScript please open an issue. There is an ongoing effort to fix this by making component props generic.

What do you think?

0reactions
joefraleycommented, Jan 20, 2022

here we are in v5.2.4 and it doesn’t seem like Select’s have their own option components. docs still using <MenuItem/>'s: https://mui.com/components/selects/

MenuItem docs make it look like <MenuItem component="" /> should be possible: https://mui.com/api/menu-item/

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Select] Prop component + value breaks compilation for ...
value , a valid prop for MenuItem (inherit from li native element) seems to break compilation, if provided along with component prop. No...
Read more >
reactjs - MUI Select custom MenuItem not working properly
In my sandbox above, you'll notice that when you select a value, the new value is not successfully displayed as the selected value....
Read more >
MenuItem Class (System.Windows.Forms)
Gets a value indicating the collection of MenuItem objects associated with the menu.
Read more >
Building an accessible menubar component using React
Libraries that provide a menubar component using React out of the box are rare. This article breaks down how to create one.
Read more >
<input>: The Input (Form Input) element - HTML
file, A control that lets the user select a file. Use the accept attribute ... Line-breaks are automatically removed from the input value....
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