Fix keyboard navigation for the dropdown menu component #10369
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes the following bugs in keyboard handling for the dropdown menu component:
componentDidMount
. Any items that are added aftercomponentDidMount
(such as "Connect Device" in the settings menu) do not get key handling.getChildren
checks for mobile viauserAgent
and not whether the menu item is visible based on screen width.All key handling has been moved up to the parent dropdown to address the first bug and the use of
offsetParent
replaces the call topxt.BrowserUtils.isMobile()
to address the second bug. This PR maintains the existing keyboard and mouse behaviour except for focussing the first menu item when the menu is opened via the keyboard using "Enter" or "Space" which is considered best practice.This screen recording demonstrates both bugs:
https://github.com/user-attachments/assets/76c7d84c-5e48-42cd-a6be-43a9c67a00b9
@microbit-matt-hillsdon