Skip to content
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

Un-revert "Add loading prop for Button and IconButton (#3582)" #4485

Merged
merged 47 commits into from
Jul 25, 2024

Conversation

mperrotti
Copy link
Contributor

@mperrotti mperrotti commented Apr 10, 2024

Brings back #3582


Copied from #3582:

Adds a loading state to both Button and IconButton. The markup follows the recommended path forward from accessibility design, and mirrors the implementation from the Export CSV button as part of GH org security coverage pages.

Implementation details

  • We use a visually hidden label instead of changing the text of the button to handle text announcements better, and to not change the size of the button.
  • aria-disabled instead of disabled to maintain focus management

New props:
loading: boolean
loadingAnnouncement: default to Loading or provide a custom message to be announced on ATs

Closes https://github.com/github/primer/issues/2680

Screenshots

CleanShot.2023-10-11.at.14.55.13.mp4
CleanShot.2023-10-11.at.14.55.42.mp4

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Changes are SSR compatible
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

Copy link

changeset-bot bot commented Apr 10, 2024

🦋 Changeset detected

Latest commit: 85c68a6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@mperrotti mperrotti changed the title Revert "Revert "Add loading prop for Button and IconButton (#3582)"" Un-revert "Add loading prop for Button and IconButton (#3582)" Apr 10, 2024
Copy link
Contributor

github-actions bot commented Apr 10, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 94.76 KB (+2.41% 🔺)
packages/react/dist/browser.umd.js 94.96 KB (+2.4% 🔺)

@github-actions github-actions bot temporarily deployed to storybook-preview-4485 April 10, 2024 15:44 Inactive
@siddharthkp siddharthkp added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Apr 10, 2024
@siddharthkp
Copy link
Member

siddharthkp commented Apr 10, 2024

Hi! There is another bug when aria-label is present, tried to address that in this PR (not merged): #4459

Should I copy those changes over here as well?

@mperrotti
Copy link
Contributor Author

@siddharthkp - yes, please copy those changes over as well

@siddharthkp
Copy link
Member

Sorry, while copying over my changes, I ran into a couple questions

On this line: https://github.com/primer/react/pull/4485/files#diff-515525e4a59d9a55e13c6c60155ec6782c78a026aae4c540c324cd8e11c83a48R102-R105,

aria-labelledby is needed because the accessible name becomes unset when the button is in a loading state.

Looking at this comment, is this still true? It looks like we set aria-describedby not label aria-label or aria-labelledby 🤔

@mperrotti
Copy link
Contributor Author

@siddharthkp I'm not sure I understand your question because we set all three depending on the situation.

We set aria-label for IconButton (see Storybook example)

We set aria-labelledby for either of these cases:

  • loading prop is true
  • aria-labelledby prop has been passed

We set aria-describedby for either of these cases:

  • loading prop is true
  • aria-describedby prop has been passed

@siddharthkp
Copy link
Member

siddharthkp commented Apr 16, 2024

Sorry, bad choice of words from me. I'll try again

Looking at this block of code: https://github.com/primer/react/pull/4485/files#diff-515525e4a59d9a55e13c6c60155ec6782c78a026aae4c540c324cd8e11c83a48R102-R105:

// aria-labelledby is needed because the accessible name becomes unset when the button is in a loading state.
// We only set it when the button is in a loading state because it will supercede the aria-label when the screen
// reader announces the button name.
aria-labelledby={loading ? `${uuid}-label` : ariaLabelledBy}

and wondering why/when accessible name becomes unset when the button is in a loading state?

I removed it that line and saw no changes which really confused me. I'm probably missing something very obvious here, thanks for your patience with me!

@mperrotti
Copy link
Contributor Author

Thanks @siddharthkp

I removed it that line and saw no changes which really confused me. I'm probably missing something very obvious here, thanks for your patience with me!

I had the same experience in the browser, but it caused the following test to fail:

 ● Button › should preserve the accessible button name when the button is in a loading state

    expect(element).toHaveAccessibleName()

    Expected element to have accessible name:
      content
    Received:

      248 |     const container = render(<Button loading>content</Button>)
      249 |
    > 250 |     expect(container.getByRole('button')).toHaveAccessibleName('content')
          |                                           ^
      251 |   })
      252 | })

@mperrotti
Copy link
Contributor Author

VRTs need to be updated now that we fixed the bug where whitespace characters were not being rendered between two elements. For example: the single-select ActionMenu button label: https://primer.style/react/storybook/?path=/story/components-actionmenu-features--single-select

@mperrotti
Copy link
Contributor Author

mperrotti commented Jul 23, 2024

I kicked off an update to the integration test PR: https://github.com/github/github/actions/runs/10066055529

@github-actions github-actions bot temporarily deployed to storybook-preview-4485 July 23, 2024 18:56 Inactive
@primer-integration
Copy link

👋 Hi from github/github! Your integration PR is ready: https://github.com/github/github/pull/334172

Copy link
Contributor

@emilybrick emilybrick left a comment

Choose a reason for hiding this comment

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

Looks good! ✨

@mperrotti mperrotti added this pull request to the merge queue Jul 25, 2024
Merged via the queue into main with commit 991839c Jul 25, 2024
30 checks passed
@mperrotti mperrotti deleted the revert-4464-revert-3582 branch July 25, 2024 13:57
@primer primer bot mentioned this pull request Jul 24, 2024
@siddharthkp siddharthkp added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Aug 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants