-
Notifications
You must be signed in to change notification settings - Fork 83
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
fix(multi-action-button): add new keyboard functionality to component FE-5188 #5235
Conversation
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:
|
Test summaryRun details
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 |
649c4d6
to
5e642c6
Compare
There was a problem hiding this 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(); |
There was a problem hiding this comment.
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.)
There was a problem hiding this comment.
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();
src/components/multi-action-button/multi-action-button.component.tsx
Outdated
Show resolved
Hide resolved
src/components/multi-action-button/multi-action-button.component.tsx
Outdated
Show resolved
Hide resolved
src/components/multi-action-button/multi-action-button.spec.tsx
Outdated
Show resolved
Hide resolved
src/components/multi-action-button/multi-action-button.spec.tsx
Outdated
Show resolved
Hide resolved
src/components/multi-action-button/multi-action-button.spec.tsx
Outdated
Show resolved
Hide resolved
src/components/multi-action-button/multi-action-button.component.tsx
Outdated
Show resolved
Hide resolved
9602181
to
5ebe6bc
Compare
9d78627
to
3ad69f1
Compare
cf2e54b
to
0c829f8
Compare
ef0885c
to
6b1dfc8
Compare
…lity into custom hook
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
5121f6a
6b1dfc8
to
5121f6a
Compare
🎉 This PR is included in version 109.3.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
fix #4522
Proposed behaviour
Updates the keyboard navigation behaviour for
MultiActionButton
andSplitButton
. 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 sameCurrent 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
QA
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]
.