Skip to content

Migrate Button component off of Bootstrap #52092

Closed

Description

@huyenltnguyen

Context

We are swapping out the Bootstrap's Button component for the ui-components one. The PR for this change is already created (#51443), but we would like to split the PR into smaller parts to ease the review process and to minimize the risk of introducing regression.

I'm opening this issue to track the PR series as well as to document issues I find during the work. The issue can be closed once all of the PRs are merged.

Goals

  • Completely remove the usage of Bootstrap Button
  • Ensure that the replacement doesn't introduce bugs
  • Opportunistically remove the existing CSS overrides in /learn
  • Adding CSS overrides may be unavoidable, but try to minimize them as the component library should already cover most of the use cases. The overrides should be accompanied with a code comment explaining the temporary state of the code.

High level approach

My plan is to split the change per page or section. Though since Button is also used in shared components, it's possible that we will have PRs that impact several pages/components. I'll see how my strategy works out as I dive in 😄

Tasks

ui-components

Learn

Activity

  1. added
    scope: UI
    platform: learn
    status: PR in works
    on Oct 25, 2023
  2. Sboonny commented on Dec 8, 2023

    @Sboonny
    Member

    Hey @huyenltnguyen, which buttons that you haven't started yet, that I can take over?

  3. huyenltnguyen commented on Dec 9, 2023

    @huyenltnguyen
    MemberAuthor

    I'm almost done with the code changes actually. and what has been taking so long is the regression testing (basically I need to check the display of each button, including all of its states) 🙂. I'll open the remaining PRs in a couple days.

  4. huyenltnguyen commented on Jan 30, 2024

    @huyenltnguyen
    MemberAuthor

    Re-opening the issue as part of the migration was reverted (#53447).

  5. ojeytonwilliams commented on Jan 30, 2024

    @ojeytonwilliams
    Contributor

    Thanks for reopening this, @huyenltnguyen.

    So, the issue was that passing href as a prop meant that onClick was ignored by the Button (and it became impossible to claim certifications).

    I'm looking into improving our test coverage. It needs to be crystal clear that something serious has gone wrong if this button stops working. That's not currently the case. Also, hopefully, TypeScript can help us here: it should be complaining if someone passes an incompatible set of props. I'll see what I can do!

  6. ojeytonwilliams commented on Jan 30, 2024

    @ojeytonwilliams
    Contributor

    I'm a little unsure what the desired behaviour is. onClick and disabled should be allowed on both types of buttons? Then the logic is: if download, href or target are passed to the Button, then show the Link component.

    Is that correct?

  7. huyenltnguyen commented on Jan 30, 2024

    @huyenltnguyen
    MemberAuthor

    Hi @ojeytonwilliams, I sincerely apologize for the mess. I'll help look into the issue as well.

    The rendering logic of this part of the codebase is quite complicated, and IMHO it is more complicated than it should be. We have some onClick logic in /learn determining whether the Button should behave like a link or an actual button, then under the hood, the Button component looks at the href prop to decide if an <a> or a <button> should be rendered.

    I'm looking into improving our test coverage. It needs to be crystal clear that something serious has gone wrong if this button stops working. That's not currently the case. Also, hopefully, TypeScript can help us here: it should be complaining if someone passes an incompatible set of props.

    I agree. I checked the behavior again on main and after the revert, and found that the behavior I expected was wrong. And I, uhm, disabled Cypress tests because I trusted myself more (which resulted a show stopper). So the path forward here is to enable the tests and scrutinize the changes I made and ensuring the new PR should pass the tests.

    onClick and disabled should be allowed on both types of buttons?

    Yes, both of them are acceptable on both button types.

    I'll need to re-check how the Button component handles onClick. But if disabled is true, Button will:

    • Set aria-disabled to true (we don't use the disabled attribute due to it having some accessibility issue)
    • Render a <button> element, as a link (<a>) cannot be disabled

    Then the logic is: if download, href or target are passed to the Button, then show the Link component.

    We only look for the truthiness of the href value. If the value is truthy, we render an <a>; otherwise, we render a <button>.


    I think the issue came from these lines:

    Notice the void operator added to the function call. It was to resolve ESLint errors, but the void operator evaluates the expression to undefined, regardless of the actual return value is, so I think it might have something to do with how the buttons behave.

    I'll try removing that and test things around.

  8. ojeytonwilliams commented on Jan 31, 2024

    @ojeytonwilliams
    Contributor

    Hi @ojeytonwilliams, I sincerely apologize for the mess. I'll help look into the issue as well.

    Thanks, I've not been following the UI Components development that closely, so I'll definitely need it. And don't worry about the bug - as a general rule, disabling tests for functionality that you're not deliberately removing is a bad idea, but that should have been caught in QA.

    onClick and disabled should be allowed on both types of buttons?
    Yes, both of them are acceptable on both button types.

    Great, thanks for confirming. That should make the types a little easier to manage.

    We only look for the truthiness of the href value. If the value is truthy, we render an ; otherwise, we render a

    Hmm. I'm pretty sure that download and target don't make sense for button elements, so we should probably switch to using a elements if any of them are truthy.

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

Metadata

Metadata

Assignees

Labels

platform: learnscope: UIstatus: PR in works

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions