Skip to content
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

[ButtonUnstyled] Update to render as link when href or to is provided #34337

Merged
merged 5 commits into from Oct 27, 2022
Merged

[ButtonUnstyled] Update to render as link when href or to is provided #34337

merged 5 commits into from Oct 27, 2022

Conversation

EduardoSCosta
Copy link
Contributor

This PR resolve #32870

With this change, the ButtonUnstyled component renders as an a element when href or to props are present, but neither component nor components.Root are provided.

@mui-bot
Copy link

mui-bot commented Sep 16, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-34337--material-ui.netlify.app/

Details of bundle changes

Generated by 🚫 dangerJS against 29ab2d6

@michaldudak michaldudak added component: button This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base labels Sep 20, 2022
Copy link
Member

@mnajdova mnajdova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very clean PR and tests 👍 Left one comment to clarify the implementaiton

const rootProps: WithOptionalOwnerState<ButtonUnstyledRootSlotProps> = useSlotProps({
elementType: Root,
getSlotProps: getRootProps,
externalForwardedProps: other,
externalForwardedProps: { ...other, href: other.href ?? other.to },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on why this is necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you expand on why this is necessary?

Without this, the href attribute doesn't appear in the html when passing only the to prop.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The to prop exists to make it easier to work with router links. It's not meant to be used as a replacement for the href. I'd pass through all the props as they are.

Side note:
This got me thinking if the Button component is doing too much. We're basically encapsulating the behavior for links and buttons under the button component. Perhaps having a LinkButtonUnstyled (or LinkUnstyled) component would allow the implementation to be cleaner? Any thoughts, @mnajdova?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got me thinking if the Button component is doing too much. We're basically encapsulating the behavior for links and buttons under the button component. Perhaps having a LinkButtonUnstyled (or LinkUnstyled) component would allow the implementation to be cleaner? Any thoughts, @mnajdova?

Button as link and Link component in my opinion are different components. On many web pages there are buttons that act as links, so supporting it in the Button component makes sense. Of course I am saying this from UI perspective, as those button looks like buttons, not links.

The Link component in my opinion is an underlined text that contains a link, which is a different UI component. So I would say 👍 for adding link component, but 👎 for removing this logic from the Button :)

@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Oct 19, 2022
@michaldudak
Copy link
Member

I resolved the conflicts caused by the recent prop renaming.

@michaldudak
Copy link
Member

Could you please merge in the latest master? Codecov shows something weird.

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now! Thanks!

@michaldudak michaldudak merged commit 9e835e4 into mui:master Oct 27, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: button This is the name of the generic UI component, not the React module! package: base-ui Specific to @mui/base
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ButtonUnstyled] Render as a if href prop is provided
4 participants