Skip to content

Conversation

@francinelucca
Copy link
Member

@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

@changeset-bot
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

@github-actions
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
@github-actions
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% 🔺)

</StyledButtonGroup>
)
})
}) as PolymorphicForwardRefComponent<'div', ButtonGroupProps>
Copy link
Member 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
@github-actions github-actions bot temporarily deployed to storybook-preview-5200 October 31, 2024 17:13 Inactive
@francinelucca francinelucca added the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Oct 31, 2024
@primer-integration
Copy link

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

@github-actions github-actions bot removed the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Oct 31, 2024
@primer primer bot temporarily deployed to github-pages October 31, 2024 17:32 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-5200 October 31, 2024 17:32 Inactive
@primer-integration
Copy link

🟢 golden-jobs completed with status success.

@github-actions
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 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
Member

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
Member 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!

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

useFocusZone({
Copy link
Member

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
Member 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!

Copy link
Member

@TylerJDev TylerJDev left a comment

Choose a reason for hiding this comment

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

Looks great ✨

@francinelucca
Copy link
Member Author

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?

I think it's fine to have both functionalities in the codebase, we're not making toolbar the default behavior for ButtonGroup but want to support accessibility-wise if that were the use case on the consumer end. ActionBar renders differently than ButtonGroup so I see how there could be valid use cases for both as toolbars depending on what the consumer is trying to do/convey. It also seems like the future of ActionBar on primer is uncertain (see https://github.slack.com/archives/GACAW0NPM/p1730231906392899) so I think we're good to move forward.

Tagging @primer/design-reviewers in case there's any thoughts

@francinelucca francinelucca added this pull request to the merge queue Nov 8, 2024
Merged via the queue into main with commit b28e6b2 Nov 8, 2024
43 checks passed
@francinelucca francinelucca deleted the francinelucca/3423-prcbuttongroup-group-container-lacks-a-role--does-not-convey-its-purpose branch November 8, 2024 17:49
@primer primer bot mentioned this pull request Nov 8, 2024
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.

6 participants