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

ProgressBar: Adjust ProgressBar.Item for accessibility #4878

Open
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

TylerJDev
Copy link
Contributor

@TylerJDev TylerJDev commented Aug 23, 2024

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

Changelog

New

Changed

  • Moves aria-* attributes to ProgressBar.Item
  • Marks ProgressBar.Item as role="progressbar"

Removed

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

Copy link

changeset-bot bot commented Aug 23, 2024

🦋 Changeset detected

Latest commit: a2ca83b

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

Copy link
Contributor

github-actions bot commented Aug 23, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 97.11 KB (-0.02% 🔽)
packages/react/dist/browser.umd.js 97.46 KB (-0.05% 🔽)

Comment on lines 64 to 75
const ariaAttributes = {
'aria-valuenow': progressAsNumber && progressAsNumber >= 0 ? Math.round(progressAsNumber) : undefined,
'aria-valuemin': 0,
'aria-valuemax': 100,
}

warning(
children &&
!ariaAttributes['aria-valuenow'] &&
typeof (rest as React.AriaAttributes)['aria-valuenow'] === 'undefined' &&
typeof (rest as React.AriaAttributes)['aria-valuetext'] === 'undefined',
'Expected `aria-valuenow` or `aria-valuetext` to be provided to <ProgressBar>. Provide one of these values so screen reader users can determine the current progress. This warning will become an error in the next major release.',
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious if there's a reason why we didn't include ariaAttributes['aria-valuenow'] as a value to include in the warning conditional? Since we automatically create the aria-valuenow based on progressAsNumber being true and a number, is that sufficient enough if consumers don't provide an aria-valuenow themselves? Also, I added progressAsNumber >= 0 so we can include aria-valuenow values that start at 0.

Cc: @kendallgassner - would love your insight, but I realize that it's been a minute since we've introduced these changes 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

huh, your right that is odd and if a user passed it in it would override the value, we are setting via ...rest. 🤔 I think it's safe to remove the warning all together.

@github-actions github-actions bot temporarily deployed to storybook-preview-4878 September 27, 2024 13:58 Inactive
@TylerJDev TylerJDev marked this pull request as ready for review September 27, 2024 14:05
@TylerJDev TylerJDev requested a review from a team as a code owner September 27, 2024 14:05
Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label Oct 18, 2024
@github-actions github-actions bot temporarily deployed to storybook-preview-4878 October 18, 2024 16:21 Inactive
@primer-integration
Copy link

primer-integration bot commented Oct 18, 2024

🟢 golden-jobs completed with status success.

@primer-integration
Copy link

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

'aria-valuemax': 100,
'aria-valuetext': progressAsNumber ? `${Math.round(progressAsNumber)}%` : undefined,
}
const validChildren = React.Children.toArray(children).length
Copy link
Member

Choose a reason for hiding this comment

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

Would https://react.dev/reference/react/Children#children-count work here as well for getting the length?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I tried this but ran into an issue where non-components would be included in the count:

<ProgressBar barSize="small" aria-label="Upload test.png">
  {false}
  {false}
  {false}
</ProgressBar>

This resulted in React.Children.count(children) to equal 3 😕 This isn't really a big deal, but I noticed this via a conditional in dotcom that was causing an error, and it was because the children were booleans instead of actual components 😅

packages/react/src/ProgressBar/ProgressBar.tsx Outdated Show resolved Hide resolved
packages/react/src/ProgressBar/ProgressBar.tsx Outdated Show resolved Hide resolved
{children ?? <Item data-animated={animated} progress={progress} bg={bg} />}
<ProgressContainer ref={forwardRef} barSize={barSize} {...rest}>
{validChildren ? (
children
Copy link
Member

Choose a reason for hiding this comment

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

For this check, would it be enough to check for the presence of children and toggle or is the count important / used somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right now, you can use the ProgressBar alone, or with children. If you use it alone, you can apply all the props directly to <ProgressBar>, but with children, you need to apply them to the individual items.

I think I understand the ask, are you asking if we can switch up the current conditional? 🤔

TylerJDev and others added 2 commits October 24, 2024 11:08
Co-authored-by: Josh Black <joshblack@github.com>
Co-authored-by: Josh Black <joshblack@github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm status: review needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants