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 keyboard navigation for the dropdown menu component #10369

Merged
merged 1 commit into from
Feb 5, 2025

Conversation

microbit-robert
Copy link
Contributor

This PR fixes the following bugs in keyboard handling for the dropdown menu component:

  • There is currently a bug where key handlers are added to the menu items on componentDidMount. Any items that are added after componentDidMount (such as "Connect Device" in the settings menu) do not get key handling.
  • On narrow screens, additional items are shown in the settings menu, however, none of these have key handling. This is because getChildren checks for mobile via userAgent 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 to pxt.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

// Check if item is intended for mobile only views
if (pxt.BrowserUtils.containsClass(child, "mobile") && !pxt.BrowserUtils.isMobile()) continue;
// Check if item is visible. Some items are intended for mobile only views.
if (!child.offsetParent) continue;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We considered using checkVisibility() here, but this appears to be too recent for the tsconfig settings.

@microbit-robert
Copy link
Contributor Author

@microsoft-github-policy-service agree company="Micro:bit Educational Foundation"

Copy link
Member

@riknoll riknoll left a comment

Choose a reason for hiding this comment

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

eventually we should move these over to the react-common implementation of menus, which handles all of this correctly. still this change is good for the meantime!

@riknoll riknoll merged commit 7bb54a3 into microsoft:master Feb 5, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants