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

fix(ButtonGroup): add toolbar interactions for role toolbar #5200

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

Conversation

francinelucca
Copy link
Contributor

@francinelucca francinelucca commented Oct 31, 2024

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

Introduces an accessibility improvement to ButtonGroup by adding correct toolbar interactions (navigate with left/right arrow instead of tab) when supplied role="toolbar".

Changelog

New

  • Test file and tests for ButtonGroup
  • Added ButtonGroup "As Toolbar" story
  • Added e2e test for new ButtonGroup "As Toolbar" story
  • Snapshots for new story

Changed

  • Export ButtonGroup as PolymorphicForwardRefComponent<'div', ButtonGroupProps>
  • Update ButtonGroup to use focusZone with left/right arrow when role="toolbar" is supplied.

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

Test deployed As Toolbar story, notice keyboard interaction. Compare to other ButtonGroup stories (these should have normal tab keyboard navigation)

Merge checklist

Copy link

changeset-bot bot commented Oct 31, 2024

🦋 Changeset detected

Latest commit: e8782e2

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 Patch

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

👋 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 31, 2024
Copy link
Contributor

github-actions bot commented Oct 31, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 98.57 KB (+0.08% 🔺)
packages/react/dist/browser.umd.js 98.87 KB (+0.07% 🔺)

{...rest}
>
{children}
</StyledButtonGroup>
)
})
}) as PolymorphicForwardRefComponent<'div', ButtonGroupProps>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Had to add this because the tests where complaining about types when trying to spread ({...props}) of type ButtonGroupProps 🤷🏽‍♀️

…-a-role--does-not-convey-its-purpose' of github.com:primer/react into francinelucca/3423-prcbuttongroup-group-container-lacks-a-role--does-not-convey-its-purpose
@primer-integration
Copy link

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

@primer-integration
Copy link

🟢 golden-jobs completed with status success.

Copy link
Contributor

github-actions bot commented Nov 1, 2024

Uh oh! @francinelucca, the image you shared is missing helpful alt text. Check #5200 (comment).

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

@francinelucca francinelucca added integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh status: review needed and removed integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm labels Nov 4, 2024
…ainer-lacks-a-role--does-not-convey-its-purpose
@francinelucca francinelucca marked this pull request as ready for review November 4, 2024 21:33
@francinelucca francinelucca requested review from a team as code owners November 4, 2024 21:33
@github-actions github-actions bot temporarily deployed to storybook-preview-5200 November 4, 2024 21:36 Inactive
/**
* Settings to apply to the Focus Zone on the ButtonGroup container component. This is only used when role="toolbar" is supplied.
*/
focusZoneSettings?: Partial<FocusZoneHookSettings>
Copy link
Member

Choose a reason for hiding this comment

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

Would there be a way to capture relevant settings people might do as props on the component, instead? Just to avoid coupling this to focusZoneSettings if we want to refactor down the line.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could potentially forgo the focusZoneSettings prop since this is well scoped for only applying if role="toolbar" is true. Since the expectations are clear on how role="toolbar" should operate with keyboard, I think it's okay if consumers aren't able to pass their own settings.

I'm thinking if they truly needed to utilize their own settings, they could just apply their own useFocusZone outside of the component, as it should replace the one that already exists, but I haven't tested so I'm not sure if it's true 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did a quick test and Tyler's right, useFocusZone in outer component will override behavior, removed focusZoneSettings here e8782e2. Thanks for the suggestion both!

forwardRef,
) {
const enabled = useFeatureFlag('primer_react_css_modules_team')
const buttonRef = useProvidedRefOrCreate(forwardRef as React.RefObject<HTMLDivElement>)

useFocusZone({
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we add focusOutBehavior: 'wrap' to the object so that it wraps when you arrow the first/last item?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done in e8782e2! Thanks so much for the suggestion 🙏🏼

…3-prcbuttongroup-group-container-lacks-a-role--does-not-convey-its-purpose
@siddharthkp
Copy link
Member

siddharthkp commented Nov 8, 2024

Probably a noob question, but do we anticipate any overlap with ActionBar, which is also a role="toolbar" with buttons and does that change our recommendation?

Both options have no usage till now, ButtonGroup with role=toolbar has 0 instances, experimental/ActionBar also has 0 instances

Copy link
Member

@siddharthkp siddharthkp left a comment

Choose a reason for hiding this comment

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

Implementation looks good!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ButtonGroup integration-tests: passing Changes in this PR do NOT cause breaking changes in gh/gh staff Author is a staff member status: review needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants