-
Notifications
You must be signed in to change notification settings - Fork 6
Fix/spatial navigation scroll bug #473
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
Conversation
| getElementsDistance(elements) { | ||
| const distances = elements.map((el) => { | ||
| const { x, y } = el.getBoundingClientRect(); | ||
| return Math.hypot(x, y); | ||
| }); | ||
|
|
||
| return Math.max(...distances); | ||
| } |
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.
Can we use reduce here to do the same. It would be something like:
| 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); | |
| } | |
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.
resolved.
| let element; | ||
| for (let i = navigatableElements.length - 1; i >= 0; i--) { | ||
| if (!navigatableElements[i].hasAttribute('disabled')) { | ||
| element = navigatableElements[i]; | ||
| break; | ||
| } | ||
| } |
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.
There is findLast method but we do not support it 😢 https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/findLast
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.
Maybe move this in a method for finding the last focused element
Note
I have concluded that there is no way to accurately calculate the next element in an element that has
scrollWidthorscrollHeightbigger than thewindow.width/height. To get around that I added anoverflowproperty 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.