fluid-lab / gamepad-navigator

GSoC 2020 project
Other
6 stars 10 forks source link

Add ability to jump to first/last focusable. #149

Open duhrer opened 5 months ago

duhrer commented 5 months ago

I had hoped that refreshing would be an easy way to get back to the top of the page. Turns out, Chrome is very nice and preserves focus on reload and now it appears also on history navigation.

We may address this in #124, but I can also see the usefulness of having something like the "home" and "end" keys on the keyboard that jumps to the beginning/end of the document. One approach would be to focus on the first/last focusable element and let the scrolling handle itself. However, this would require careful naming, as it won't necessarily scroll all the way to the top or down to the bottom.

Another idea is to scroll and then set the current tabbable elements index to something out of bounds. For example, setting it to -1 would jump to the first element on the page when the right bumper is hit, and jump to the last element if the left bumper is hit.

For scrolling down, we'd set the value to the number of tabbables, and let our internal wrapping ensure that the right bumper would "wrap" to the top, and the left bumper would navigate to the last element on the page.