Skip to content

Conversation

@MartinBozhilov-coh
Copy link
Contributor

  • Self-reviewed and fixed any obvious mistakes, TODOs, removed debugging code, logs, etc
  • Updated package.json in related components, the library or the cli
  • Tested in a browser
  • Tested in Gameface

Note

I have concluded that there is no way to accurately calculate the next element in an element that has scrollWidth or scrollHeight bigger than the window.width/height . To get around that I added an overflow property to the navigation area object which will hold the difference between the height of the overflowing element and the viewport. If there isn't it will just be 0.

Comment on lines 155 to 162
getElementsDistance(elements) {
const distances = elements.map((el) => {
const { x, y } = el.getBoundingClientRect();
return Math.hypot(x, y);
});

return Math.max(...distances);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use reduce here to do the same. It would be something like:

Suggested change
getElementsDistance(elements) {
const distances = elements.map((el) => {
const { x, y } = el.getBoundingClientRect();
return Math.hypot(x, y);
});
return Math.max(...distances);
}
getElementsDistance(elements) {
return elements.reduce((acc, el) => {
const { x, y } = el.getBoundingClientRect();
const distance = Math.hypot(x, y);
acc = acc < distance ? distance : acc;
}, 0);
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

resolved.

Comment on lines +515 to +521
let element;
for (let i = navigatableElements.length - 1; i >= 0; i--) {
if (!navigatableElements[i].hasAttribute('disabled')) {
element = navigatableElements[i];
break;
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe move this in a method for finding the last focused element

@MartinBozhilov-coh MartinBozhilov-coh merged commit 523c13d into master Apr 7, 2025
2 of 4 checks passed
@MartinBozhilov-coh MartinBozhilov-coh deleted the fix/spatial-navigation-scroll-bug branch April 7, 2025 13:15
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.

3 participants