Skip to content

refactor: swap Button component - #51443

Closed
Sboonny wants to merge 13 commits into
freeCodeCamp:mainfrom
Sboonny:refactor/replace-button-component
Closed

Sboonny wants to merge 13 commits into
freeCodeCamp:mainfrom
Sboonny:refactor/replace-button-component

Conversation

@Sboonny

@Sboonny Sboonny commented Aug 31, 2023

Copy link
Copy Markdown
Member

Checklist:

Closes #XXXXX

@Sboonny
Sboonny requested a review from a team August 31, 2023 05:31
@github-actions github-actions Bot added platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc. labels Aug 31, 2023
@Sboonny
Sboonny marked this pull request as draft August 31, 2023 05:32
@ghost

ghost commented Aug 31, 2023 •

Copy link
Copy Markdown

👀 Review this PR in a CodeSee Review Map

View the CodeSee Map of this change

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

Comment on lines +7 to +12
export interface ButtonProps<TElement = HTMLButtonElement>
extends React.ButtonHTMLAttributes<TElement> {
children: React.ReactNode;
variant?: ButtonVariant;
size?: ButtonSize;
onClick?: MouseEventHandler<HTMLButtonElement | HTMLAnchorElement>;
onClick?: MouseEventHandler<TElement>;

@Sboonny Sboonny Aug 31, 2023 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

had to change the type, to fix this error

image

@Sboonny

Sboonny commented Sep 8, 2023 •

Copy link
Copy Markdown
Member Author

ToDo:

  • disable the buttons that has aria-disabled while aren't disabled, mostly the submit challenges buttons.
  • add the margin-top to the tool-panel, the best solution for now is to add Spacer, Spacer add more than needed space, added inline because I can't keep it modular without using inline styles.

@Sboonny Sboonny mentioned this pull request Sep 19, 2023
37 of 49 tasks
Comment on lines +113 to +111
{...(isDisabled && {
onInvalid: (e: React.FormEvent<HTMLInputElement>) =>
e.preventDefault()
})}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

needed to use this, to mimic disabled behavior, because we are using aria-disabled.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@Sboonny
Sboonny marked this pull request as ready for review October 5, 2023 12:25
@Sboonny

Sboonny commented Oct 5, 2023 •

Copy link
Copy Markdown
Member Author

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.

@Sboonny Sboonny added the status: blocked In a transient & temporary hold. label Oct 10, 2023
Sboonny and others added 9 commits October 17, 2023 10:54
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
Comment on lines -59 to -74
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();
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@Sboonny Sboonny removed the status: blocked In a transient & temporary hold. label Oct 17, 2023
@Amit-Morade

Copy link
Copy Markdown

Can I work on this

@ahmaxed

ahmaxed commented Oct 18, 2023

Copy link
Copy Markdown
Member

@Amit-Morade, feel free to review it if you wish by comparing the buttons on this branch with production.

@ahmaxed ahmaxed added the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Oct 18, 2023
@huyenltnguyen huyenltnguyen self-assigned this Oct 19, 2023

@huyenltnguyen huyenltnguyen left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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
Screenshot 2023-10-20 at 17 54 34 Screenshot 2023-10-20 at 17 31 20

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.

@Sboonny

Sboonny commented Oct 21, 2023

Copy link
Copy Markdown
Member Author

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.

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 /learn acts weird when you build certain components, it has acted weirdly when I tried to migrate Container, Col, Row and Form Components, but it doesn't hurt to try if the review process is hard.

}

.btn-cta {
.default-layout .btn-cta {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Specificity issue, tailwind styles were overriding the class styles

}

button:hover,
button:hover:not([aria-disabled='true'], [role='menuitem'], .map-title),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

Comment on lines +1 to +4
.tool-panel-group > button,
#get-help-dropdown {
margin-top: 5px;
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

reset would stack on top of get help button, added space to account for that

}

.block .map-cert-title {
.cert-block .map-cert-title {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

block is a classname that affect tailwind, needed to change it to something that doesn't hook to it

@Sboonny

Sboonny commented Oct 22, 2023 •

Copy link
Copy Markdown
Member Author

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.

@huyenltnguyen

Copy link
Copy Markdown
Member

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 🙂

@Sboonny

Sboonny commented Oct 23, 2023

Copy link
Copy Markdown
Member Author

Thank you

@huyenltnguyen

huyenltnguyen commented Oct 26, 2023 •

Copy link
Copy Markdown
Member

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.

@huyenltnguyen
huyenltnguyen marked this pull request as draft October 26, 2023 04:59
@Sembauke Sembauke removed the status: waiting review To be applied to PR's that are ready for QA, especially when additional review is pending. label Oct 27, 2023
@huyenltnguyen

Copy link
Copy Markdown
Member

I've split the changes into smaller PRs, and thus am going to close this one.

@Sboonny Thanks again for the work here :)

@Sboonny
Sboonny deleted the refactor/replace-button-component branch December 29, 2023 14:43
@Sboonny

Sboonny commented Dec 29, 2023

Copy link
Copy Markdown
Member Author

Awesome, thank you for taking care of it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform: learn UI side of the client application that needs familiarity with React, Gatsby etc. scope: tools/scripts Scripts for supporting dev work, generating config and build artifacts, etc.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants