Skip to content

[ButtonBase] The LinkComponent prop does not take effect when set in MenuItem #28335

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

Closed
aress31 opened this issue Sep 14, 2021 · 3 comments
Closed
Labels
component: ButtonBase The React component. status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it

Comments

@aress31
Copy link

aress31 commented Sep 14, 2021

I already opened a ticket about this specific bug but it was quickly discarded without any serious investigation, see #28251.

The bug is that MuiListItemButton and MuiMenuItem (subclasses of MuiButtonBase) are not inheriting the LinkComponent prop of MuiButtonBase and this despite the doc clearly stating that both of these components should inherit from MuiButtonBse, see:

Props of the ButtonBase component are also available.

Could you kindly investigate this issue?

CodeSandbox: https://codesandbox.io/s/mui-28251-28335-p7krh

@aress31 aress31 added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Sep 14, 2021
@mnajdova
Copy link
Member

mnajdova commented Sep 16, 2021

The props are forwarded to the ButtonBase component. However, the logic in the ButtonBase component is the following: it considers the LinkComponent property, only if the component prop is not set and there is a href on the component. The MenuItem is already setting the component prop to 'li'. So, in order to fix this, you need to use the component prop directly. See https://codesandbox.io/s/mui-28251-28335-forked-wdq76?file=/src/App.js (something is failing after the component is set, but I will leave this to you :))

I've seen several issues around the LinkComponent and when this prop is being considered, in my opinion we should maybe drop it in v6 in favor of the components and componentsProps API.

@mnajdova mnajdova added component: ButtonBase The React component. status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Sep 16, 2021
@mnajdova mnajdova changed the title MuiButtonBase Props Not Passed Down to Children [ButtonBase] The LinkComponent prop does not take effect when set in MenuItem Sep 16, 2021
@aress31
Copy link
Author

aress31 commented Sep 16, 2021

Thanks for the detailed information, it is indeed confusing.

@aress31 aress31 closed this as completed Sep 16, 2021
@NathanC
Copy link

NathanC commented Jul 30, 2022

FYI for anyone having this issue, the workaround of using component currently doesn't work because the component prop is missing. See #33710

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ButtonBase The React component. status: expected behavior Does not imply the behavior is intended. Just that we know about it and can't work around it
Projects
None yet
Development

No branches or pull requests

3 participants