-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Select] Prop component + value breaks compilation for MenuItem #21210
Comments
This is unfortunately expected since this only works because you've wrapped the We'll fix this in v5 where we will have a dedicated component for |
First of all, thank you for taking the time to answer, and adding this issue to the milestone. I really appreciate it. Your thought makes sense, but I've tried replacing the select with a fragment and the compilation still broken for the same cases. Is this still related to the underneath |
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:
What do you think? |
I think I'm hitting the same issue with NextJs's Link: import { forwardRef, Ref } from "react";
import Link, { LinkProps } from "next/link";
import { MenuItem, MenuItemProps } from "@material-ui/core";
type Props = MenuItemProps & Pick<LinkProps, "href" | "as" | "prefetch" | "locale">;
const LinkMenuItem = ({ href, as, prefetch, locale, ...props }: Props, ref: Ref<HTMLLIElement>) => (
<Link href={href} as={as} prefetch={prefetch} locale={locale} passHref>
{/* @ts-ignore https://github.com/mui-org/material-ui/issues/21210 probably going to be fixed in mui v5 */}
<MenuItem component="a" ref={ref} {...props} />
</Link>
);
export default forwardRef<HTMLLIElement, Props>(LinkMenuItem); This code gives me Although it does render and work correctly, and doesnt throw anything in the console. |
here we are in v5.2.4 and it doesn't seem like MenuItem docs make it look like |
Combination of both prop
component
+ propvalue
seems incompatible.Current Behavior 😯
value
, a valid prop forMenuItem
(inherit fromli
native element) seems to break compilation, if provided along withcomponent
prop. No matter ifcomponent
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 tovalue
, Typescript complains for line 15I'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 🌎
The text was updated successfully, but these errors were encountered: