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(multi-action-button): add new keyboard functionality to component FE-5188 #5235

Merged

Conversation

edleeks87
Copy link
Contributor

@edleeks87 edleeks87 commented Jun 16, 2022

fix #4522

Proposed behaviour

Updates the keyboard navigation behaviour for MultiActionButton and SplitButton. Up and down arrow keys can still be used for navigating children buttons but there is no longer any looping back around. When the children container is open tabbing can now be used to navigate the children buttons, the tab key takes you down the list and back tab goes up. When the last child button is focused and tab is pressed it will close the container and move focus to the next focusable element on the page. When the shift and tab keys are pressed and the first child button is focused it will close the container and return focus back to the main button control. Pressing the escape key when the children container is open will now close the list and return focus back to the main button control. All other keyboard functionality remains the same

Current behaviour

Up and down arrow keys navigate children buttons and loop back around. Tabbing moves focus away from the children buttons to the next element on the page, back tabbing moves focus back to main button control

Checklist

  • Commits follow our style guide
  • Related issues linked in commit messages if required
  • Unit tests added or updated if required

QA

  • Tested in CodeSandbox/storybook
  • Add new Cypress test coverage if required
  • Carbon implementation matches Design System/designs
  • UI Tests GitHub check reviewed if required

Additional context

Testing instructions

Can be tested in storybook

The following CodeSandbox is an example of the broken behaviour.
You can see the new behaviour by looking at the version in the comment by codesandbox[bot].

@codesandbox-ci
Copy link

codesandbox-ci bot commented Jun 16, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 5121f6a:

Sandbox Source
carbon-quickstart Configuration
carbon-quickstart-typescript Configuration
carbon-quickstart PR
serene-spence-7dv4bf Issue #4522

@cypress
Copy link

cypress bot commented Jun 16, 2022



Test summary

2446 0 2 0Flakiness 0


Run details

Project carbon
Status Passed
Commit 5121f6a
Started Jul 19, 2022 12:23 PM
Ended Jul 19, 2022 12:29 PM
Duration 06:08 💡
OS Linux Debian - 10.10
Browser Chrome 100

View run in Cypress Dashboard ➡️


This comment has been generated by cypress-bot as a result of this project's GitHub integration settings. You can manage this integration in this project's settings in the Cypress Dashboard

@edleeks87 edleeks87 force-pushed the FE-5188-esc-key-fix-for-multi-action-and-split-button branch from 649c4d6 to 5e642c6 Compare June 16, 2022 13:10
@robinzigmond robinzigmond self-requested a review June 21, 2022 15:14
Copy link
Contributor

@robinzigmond robinzigmond left a comment

Choose a reason for hiding this comment

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

A couple of general points:

Having done a quick test, I think there's a few requirements given on FE-5188 that this PR doesn't meet:

  • when focusing on the parent button and pressing the up arrow, the menu doesn't open
  • holding command while pressing up or down arrow only moves up/down once, when according to the requirements it should move focus all the way to the first/last menu item. (Control+up/down should do the same on Windows, as should the Home/End buttons - might need some investigation into how presses on those buttons are sent to the browser.)

Also, as a general point: there's so much code here replicated between Multi Action Button and Split Button, can't we DRY it up a bit, at least with some utils perhaps to handle the keyboard functionality? I recognise it was like this before, but I'd have been very tempted to do this if I was rewriting it anyway as you are. Will leave it to your better judgement!

Needless to say, most/all of my many comments on the MultiActionButton changes also apply to SplitButton

buttonRef.current as HTMLButtonElement
);

elements[indexOf]?.focus();
Copy link
Contributor

Choose a reason for hiding this comment

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

I realise this wasn't your code and existed before, but is all this really necessary? We're finding the index of buttonRef.current in the elements array, then grabbing the element at that index, and focusing it. In other words, we're focusing the main button which should be accessible at buttonRef.current.

At the risk of sounding stupid, why can't we do this with just buttonRef.current?.focus ?? (I'm not even sure the ?. is needed there but it does no harm and prevents crashes in potential weird situations.)

Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that according to the new requirements it should be elements[indexOf + 1]?.focus();

@mkrds mkrds self-requested a review June 23, 2022 11:42
@edleeks87 edleeks87 force-pushed the FE-5188-esc-key-fix-for-multi-action-and-split-button branch 2 times, most recently from 9602181 to 5ebe6bc Compare June 27, 2022 15:46
robinzigmond
robinzigmond previously approved these changes Jun 28, 2022
@edleeks87 edleeks87 force-pushed the FE-5188-esc-key-fix-for-multi-action-and-split-button branch 2 times, most recently from 9d78627 to 3ad69f1 Compare June 28, 2022 10:20
@edleeks87 edleeks87 force-pushed the FE-5188-esc-key-fix-for-multi-action-and-split-button branch 3 times, most recently from cf2e54b to 0c829f8 Compare June 28, 2022 15:06
mkrds
mkrds previously approved these changes Jun 29, 2022
robinzigmond
robinzigmond previously approved these changes Jun 29, 2022
@edleeks87 edleeks87 marked this pull request as ready for review June 29, 2022 08:10
@edleeks87 edleeks87 requested review from a team as code owners June 29, 2022 08:10
@edleeks87 edleeks87 dismissed stale reviews from robinzigmond and mkrds via 3e487aa July 18, 2022 10:34
@edleeks87 edleeks87 force-pushed the FE-5188-esc-key-fix-for-multi-action-and-split-button branch 3 times, most recently from ef0885c to 6b1dfc8 Compare July 18, 2022 11:07
robinzigmond
robinzigmond previously approved these changes Jul 18, 2022
mkrds
mkrds previously approved these changes Jul 18, 2022
DlgSHi
DlgSHi previously approved these changes Jul 19, 2022
edleeks87 and others added 3 commits July 19, 2022 13:10
Implements `useMenuKeyboardNavigation` to Update the keyboard navigation behaviour
for `MultiActionButton`. Up and down arrow keys can still be used for navigating
children buttons but there is no longer any looping back around. When the children
container is open tabbing can now be used to navigate the children buttons, the tab
key takes you down the list and back tab goes up. When the last child button is
focused and tab is pressed it will close the container and move focus to the next
focusable element on the page. When the shift and tab keys are pressed and the first
child button is focused it will close the container and return focus back to the main
button control. Pressing the escape key when the children container is open will now
close the list and return focus back to the main button control. All other keyboard
functionality remains the same

fix #4522
Implements `useMenuKeyboardNavigation` to update the keyboard navigation behaviour
for `SplitButton`. Up and down arrow keys can still be used for navigating children
buttons but there is no longer any looping back around. When the children container
is open tabbing can now be used to navigate the children buttons, the tab key takes
you down the list and back tab goes up. When the last child button is focused and
tab is pressed it will close the container and move focus to the next focusable
element on the page. When the shift and tab keys are pressed and the first child
button is focused it will close the container and return focus back to the main
button control. Pressing the escape key when the children container is open will
now close the list and return focus back to the main button control. All other
keyboard functionality remains the same

fix #4522
@edleeks87 edleeks87 dismissed stale reviews from DlgSHi, mkrds, and robinzigmond via 5121f6a July 19, 2022 12:18
@edleeks87 edleeks87 force-pushed the FE-5188-esc-key-fix-for-multi-action-and-split-button branch from 6b1dfc8 to 5121f6a Compare July 19, 2022 12:18
@edleeks87 edleeks87 merged commit e3996a4 into master Jul 19, 2022
@edleeks87 edleeks87 deleted the FE-5188-esc-key-fix-for-multi-action-and-split-button branch July 19, 2022 12:31
@carbonci
Copy link
Collaborator

🎉 This PR is included in version 109.3.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

Multi Action Button can't close with Esc key
7 participants