Skip to content

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

Merged
francinelucca merged 8 commits into
mainfrom
francinelucca/3423-prcbuttongroup-group-container-lacks-a-role--does-not-convey-its-purpose
Nov 8, 2024
Merged

fix(ButtonGroup): add toolbar interactions for role toolbar#5200
francinelucca merged 8 commits into
mainfrom
francinelucca/3423-prcbuttongroup-group-container-lacks-a-role--does-not-convey-its-purpose

Conversation

@francinelucca

@francineluccafrancinelucca commented Oct 31, 2024

Copy link
Copy Markdown
Member

Closeshttps://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

changeset-botBot commented Oct 31, 2024

Copy link
Copy Markdown

🦋 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
NameType
@primer/reactPatch

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
Copy Markdown
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-actionsgithub-actionsBot 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

github-actionsBot commented Oct 31, 2024

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
packages/react/dist/browser.esm.js98.57 KB (+0.08% 🔺)
packages/react/dist/browser.umd.js98.87 KB (+0.07% 🔺)

</StyledButtonGroup>
)
})
}) as PolymorphicForwardRefComponent<'div', ButtonGroupProps>

Copy link
Copy Markdown
MemberAuthor

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-actionsBottemporarily deployed to storybook-preview-5200 October 31, 2024 17:13 Inactive
@francineluccafrancinelucca added the update snapshots 🤖 Command that updates VRT snapshots on the pull request label Oct 31, 2024
@primer-integration

Copy link
Copy Markdown

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

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

Copy link
Copy Markdown

🟢 golden-jobs completed with status success.

@github-actions

Copy link
Copy Markdown
Contributor

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.

@francineluccafrancinelucca 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 ownersNovember 4, 2024 21:33
@github-actions
github-actionsBottemporarily 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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
MemberAuthor

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
Copy Markdown
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
Copy Markdown
MemberAuthor

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

siddharthkp commented Nov 8, 2024

Copy link
Copy Markdown
Member

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

@siddharthkpsiddharthkp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Implementation looks good!

@TylerJDevTylerJDev left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
MemberAuthor

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 queueNov 8, 2024
Merged via the queue into main with commit b28e6b2Nov 8, 2024
@francinelucca
francinelucca deleted the francinelucca/3423-prcbuttongroup-group-container-lacks-a-role--does-not-convey-its-purpose branch November 8, 2024 17:49
@primerprimerBot mentioned this pull request Nov 8, 2024
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: ButtonGroupintegration-tests: passingChanges in this PR do NOT cause breaking changes in gh/ghstaffAuthor is a staff memberstatus: review needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

@francinelucca@siddharthkp@joshblack@langermank@TylerJDev