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(web): fix asset grid keyboard navigation #9448

Merged
merged 5 commits into from
May 24, 2024

Conversation

Snowknight26
Copy link
Contributor

@Snowknight26 Snowknight26 commented May 14, 2024

Fixes #9446

@Snowknight26
Copy link
Contributor Author

Snowknight26 commented May 14, 2024

This change removes the keydown binds in favor of the browser handling those respective keys. This also makes arrow keys work as expected.

However, the element has to be focused first.

Not sure how things like Google Photos get away with having an inner element scroll even though the element that receives the KeyboardEvent is the body, just like Immich does. Tried debugging it and I can't see what they're doing differently to cause scrolling to occur on the "correct" element. Even adding the appropriate role attribute to the section element we want to scroll, changing it so there's only one main element in the DOM, adding tabindex.. nada.

@Snowknight26
Copy link
Contributor Author

Think I figured it out. It's possible to focus on an element while the keyDown event handler runs, and so long as the event doesn't have preventDefault called on it, it'll be passed to the now-focused element.
This allows us to have an event listener on window that passes focus to the asset grid, that then forwards the KeyboardEvent to the asset grid. With the addition of tabindex="-1", the asset grid is now focusable, and keyboard navigation works.

Currently only PageDown/PageUp trigger the focus, to match the product that shall not be named, but once focus is given to the asset grid, arrow keys and home/end also work as expected.

@Snowknight26 Snowknight26 marked this pull request as ready for review May 15, 2024 01:43
Copy link
Member

@danieldietzler danieldietzler left a comment

Choose a reason for hiding this comment

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

Awesome, thank you for figuring that out!

@danieldietzler danieldietzler merged commit 847cb90 into immich-app:main May 24, 2024
22 of 24 checks passed
@Snowknight26 Snowknight26 deleted the fix-page-down-shortcut branch May 25, 2024 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Page up and page down keys now scroll to top and bottom of page
3 participants