Repository navigation
Conversation
|
👀 Review this PR in a CodeSee Review Map |
| export interface ButtonProps<TElement = HTMLButtonElement> | ||
| extends React.ButtonHTMLAttributes<TElement> { | ||
| children: React.ReactNode; | ||
| variant?: ButtonVariant; | ||
| size?: ButtonSize; | ||
| onClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>; | ||
| onClick?: MouseEventHandler<TElement>; |
|
ToDo:
|
| {...(isDisabled && { | ||
| onInvalid: (e: React.FormEvent<HTMLInputElement>) => | ||
| e.preventDefault() | ||
| })} |
There was a problem hiding this comment.
needed to use this, to mimic disabled behavior, because we are using aria-disabled.
There was a problem hiding this comment.
Could you elaborate on this change? If we want to ignore the click event, would adding this logic to the ui-components's Button be sufficient?
There was a problem hiding this comment.
the disabled attribute doesn't trigger an invalid event in the input, when the button is clicked, while the aria-disabled does because it doesn't drop or interact with the event if aria-disabled is true.
a hint for this is when the new button is clicked, it has an outline to indicate focused, while the old one doesn't.
If we want to ignore the click event, would adding this logic to the
ui-components's Button be sufficient?
Depend on the path we take to make it not need in the /learn.
If we revert the morphing of disabled to aria-disabled, and let the consumers assign disabled, aria-disabled, and aria-pressed however they see fit, then it will be sufficient to not trigger the click event, so the invalid event won't trigger.
And if we disable the click event, entirely in the library, depend on how it applied, we may be creating disabled again, and removing the ability to read the button on specific screen readers, or create weird behaviors and edge cases.
And if we check "is there is a form input next to the button?" would lead to annoying behavior and coupling of concerns.
To be honest, I don't want to create these logics, and prefer to revert the disabled and aria-disabled, if this will be an issue, because I don't know how the button is going to be used in the future, I prefer letting the consumer deal with it.
|
The failing test is solved in the form #51204, we can merge the form PR first to avoid repeating the work. This should be ready for review. |
fix type error import the button for the rest of the components delete extra button added fix prettier fix eslint clean extra css properties WIP: sort specificity issue update the snapshot sort the missing margin update the test align our usage with the old button styles remove extra import fix type error update the new buttons in donation modal update the snapshot disabled input validation when the button is disabled format prettier WIP: sort the tests sort the tests? refacoter the onclick function pass the onclick to the anchor
| it('should not trigger the onClick prop if the button is disabled', () => { | ||
| const onClick = jest.fn(); | ||
|
|
||
| render( | ||
| <Button disabled onClick={onClick}> | ||
| Hello world | ||
| </Button> | ||
| ); | ||
|
|
||
| const button = screen.getByRole('button', { name: /hello world/i }); | ||
|
|
||
| userEvent.click(button); | ||
|
|
||
| expect(onClick).not.toBeCalled(); | ||
| }); | ||
|
|
There was a problem hiding this comment.
removed this, because we don't need the function to not be called when it's disabled, but need to make the function not do anything similar to how we were doing it in the form submission, and going the old way was causing bugs.
|
Can I work on this |
|
@Amit-Morade, feel free to review it if you wish by comparing the buttons on this branch with production. |
There was a problem hiding this comment.
Hey @Sboonny, thank you for this work!
I'm still slowly going through the changes, but it'd be great if you provide some context on the CSS changes in the PR.
So far I found that we have a regression on the donate page (/donate), in the hover state of the accordion:
| Light | Dark |
|---|---|
![]() |
![]() |
I'm wondering if it's possible that we could split this PR into multiple smaller parts, maybe we move the straight-forward swaps into one PR, and the more involved ones into others. That would be much easier to review, and shipping the changes would also be a little less risky.
Let me know what you think and if you need my help with the split.
It is possible, I haven't done it because if I wanted to revert the component's PRs, if they break production somehow, through as fewer PRs as possible, so I don't miss something, and the |
| } | ||
|
|
||
| .btn-cta { | ||
| .default-layout .btn-cta { |
There was a problem hiding this comment.
Specificity issue, tailwind styles were overriding the class styles
| } | ||
|
|
||
| button:hover, | ||
| button:hover:not([aria-disabled='true'], [role='menuitem'], .map-title), |
There was a problem hiding this comment.
This was overriding the tailwind styles, you will need to use class instead of the :not to reduce complexity, but this is a quick patch for the issue
| .tool-panel-group > button, | ||
| #get-help-dropdown { | ||
| margin-top: 5px; | ||
| } |
There was a problem hiding this comment.
reset would stack on top of get help button, added space to account for that
| } | ||
|
|
||
| .block .map-cert-title { | ||
| .cert-block .map-cert-title { |
There was a problem hiding this comment.
block is a classname that affect tailwind, needed to change it to something that doesn't hook to it
|
Sorry @huyenltnguyen, I can't currently commit to creating smaller PRs for the swapping, as I don't have the same time, I had when I started. If you think the best way to make it less buggy is to make it smaller, feel free to close this and open small ones, don't worry about attribute, co-author and stuff alike because I don't care about them. |
|
Thanks @Sboonny! I hope things are okay over there. You've done a lot already, and I'll be happy to handle the rest to get this in 🙂 |
|
Thank you |
|
I've created #52092 to track the PR split. I'm going to convert the PR to draft so take it off the reviewers' radar. |
|
I've split the changes into smaller PRs, and thus am going to close this one. @Sboonny Thanks again for the work here :) |
|
Awesome, thank you for taking care of it. |




Checklist:
mainbranch of freeCodeCamp.Closes #XXXXX