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
[ButtonUnstyled] Update to render as link when href or to is provided #34337
Conversation
… without component or components.Root props
|
There was a problem hiding this 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 }, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
:)
I resolved the conflicts caused by the recent prop renaming. |
Could you please merge in the latest master? Codecov shows something weird. |
There was a problem hiding this 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!
…mui#34337) Co-authored-by: Michał Dudak <michal@dudak.me>
…mui#34337) Co-authored-by: Michał Dudak <michal@dudak.me>
This PR resolve #32870
With this change, the
ButtonUnstyled
component renders as ana
element whenhref
orto
props are present, but neithercomponent
norcomponents.Root
are provided.