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 isFocusable for FocusList component #10378

Merged
merged 2 commits into from
Feb 12, 2025

Conversation

microbit-robert
Copy link
Contributor

@microbit-robert microbit-robert commented Feb 10, 2025

Focus appears to get stuck while using the keyboard to navigate the versions in the "Version History" feature when parent tree items are not expanded. See the point at which focus becomes stuck in the screenshot below:

image

The isFocusable method checks the visibility of the sub-tree item using its computed display property, but this does not take into account that the item's parent div is hidden.

This PR uses offsetParent as an alternative approach to checking element visibility. In addition, findNextFocusableElement now passes the optional isFocusable argument to itself when called recursively.

The getComputedStyle approach is still used in findNextFocusableElement as a fallback, but perhaps not unreasonably so.

@microbit-matt-hillsdon

@@ -59,7 +59,7 @@ export const FocusList = (props: FocusListProps) => {

const isFocusable = (e: HTMLElement) => {
return e.getAttribute("data-isfocusable") === "true"
&& getComputedStyle(e).display !== "none";
&& !!e.offsetParent;
Copy link
Member

Choose a reason for hiding this comment

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

i think this should be an explicit check for null, 0 is a valid value here, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch, yes. Changed here 51196b7.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second look it returns a reference to an element rather than an offset value, but this change does no harm. Not the best property name in the world.

@riknoll riknoll merged commit d43f4c8 into microsoft:master Feb 12, 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