Repository navigation
feat(ui-components): add support for link to Button component - #45671
Conversation
|
👀 Review this PR in a CodeSee Review Map |
8cc457b to
19d2b06
Compare
| if (to) { | ||
| return renderLink(); | ||
| } else { | ||
| return renderButton(); | ||
| } |
There was a problem hiding this comment.
The rendering logic here is a bit complicated in order to make our component semantically correct:
- If the
toprop is defined, we render anaelement - If both
toanddisabledare defined, we render abuttonelement because a link cannot be disabled - If the
toprop is not defined, we render abuttonelement
There was a problem hiding this comment.
As a matter of curiosity, when would there be both a to and disabled?
There was a problem hiding this comment.
Hopefully, never :), just in case we pass both by mistake the element would just return a button element.
There was a problem hiding this comment.
Yup. This is me being paranoid. There should never be a case where both to and disabled are passed in.
I believe we can enforce this rule with TypeScript using union types, but the typing ended up a bit crazy in my initial attempt, so I decided to just keep the interface as-is and silently handle invalid use case for now.
|
So this should be a button that looks like a link. I know it does not follow the best practices, so I will prioritize a/b testing an alternative as soon as we ship our component library. Finally, we would need to add onClick as an action in argTypes in a separate pr perhaps. That insures all props are documented. |
This one is a link that looks like a button actually 😅 It will be used for the Download your data "button" on the Settings page. The rendering approach I'm following is to make our Button behave similar to the Bootstrap one, in that it can be a real What alternative do you have in mind? |
|
@huyenltnguyen, my bad. I thought you were working on the Link variation described in #45357. The logic makes sense. It seems more intuitive to me to ignore the disable prop and return a link when href prop is provided, but feel free to ignore this suggestion if the current logic makes more sense to you. The only nitpick is that the text does not center for the button styled link when the block prop is passed. Finally, we would need to get the link styled button before closing this issue. |
|
Oh @ahmadabdolsaheb, guess what, I thought I posted this in the issue thread, but I realized that I have not. Regarding the link styled thing, I was wondering if it would be more appropriate as a Link component with the |
|
ok |

Checklist:
Update index.md)mainbranch of freeCodeCamp.Closes #45357.
This PR:
Note: I mentioned the ButtonGroup component in the issue for completeness, but since there isn't a use case for it yet, I think we can ignore it for now.
Screenshots