Fix keyboard navigation scrolling in dropdowns#26358
Conversation
src/main/js/util/keyboard.js
Outdated
| if (!isInViewport(selectedItem)) { | ||
| selectedItem.scrollIntoView(false); | ||
| } | ||
| selectedItem.scrollIntoView({ block: "center", behavior: "smooth" }); |
There was a problem hiding this comment.
Whilst this does fix the bug (which is the priority) it is scrolling too early and its a bit jumpy.
Could you investigate if the isInViewport function could be fixed instead? as I assume that was intended to only scroll when needed. (cc @mawinter69 as the author of that change)
the block: center does seem better. When it was anchored to the bottom which is what false does it was good when going down but when going back up it was a bit strange feeling.
There was a problem hiding this comment.
Good point. I tested with block: 'nearest' initially, which only scrolls when needed, but it didn't show section headers when wrapping from bottom to top (e.g. selecting "System" didn't show the "Actions" and "System Configuration" header above it).

The isInViewport function checks if the element is in the browser window, not the dropdown container. Items scrolled out of view in the dropdown still pass the check because they're technically in the window, so scrolling never triggers.
I can fix isInViewport to check visibility within the dropdown bounds instead. That would keep the "only scroll when needed" behavior while fixing the bug. Want me to go that route?
There was a problem hiding this comment.
I can fix isInViewport to check visibility within the dropdown bounds instead. That would keep the "only scroll when needed" behavior while fixing the bug. Want me to go that route?
Give it a go, would be better if it was less jarring, but if we can't get something nicer at least this works.
There was a problem hiding this comment.
Will update to check dropdown container visibility. Testing now !
There was a problem hiding this comment.
Could you investigate if the
isInViewportfunction could be fixed instead? as I assume that was intended to only scroll when needed. (cc @mawinter69 as the author of that change)
Tried fixing isInViewport to check dropdown container visibility but ran into issues, the dropdown doesn't have a max-height in the DOM, so it sizes to fit all items and visibility checks always pass.
The "nearest" approach scrolls smoothly and only when needed.
Minor edge case: section headers don't always show when wrapping bottom to top, but navigation works fine.
Video attached.
dropdown.with.nearest.fix.mp4
Worth committing or should try something else?
timja
left a comment
There was a problem hiding this comment.
Tested locally, this works a lot better.
Yes the headings don't show when you loop back around when scrolling but meh its fine.
Thanks!
If you're looking for another similar issue, while testing this fix I noticed (and reported) https://github.com/jenkinsci/jenkins/issues/26378
|
Thanks for testing! Will check out the ticket. |
|
/label ready-for-merge This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback. Thanks! |
|
Congratulations on getting your very first Jenkins core pull request merged 🎉🥳 |
Fixes #26357
Testing done
Screenshots (UI changes only)
Before
Arrow key navigation selected items but didn't scroll, making off-screen items invisible.
dropdown.scrolling.defect.mp4
After
Dropdown scrolls smoothly to center the selected item when navigating with arrow keys.
fix.dropdown.scrolling.mp4
Proposed changelog entries
Proposed changelog category
/label bug
Proposed upgrade guidelines
N/A
Submitter checklist
@Restrictedor have@since TODOJavadocs, as appropriate.@Deprecated(since = "TODO")or@Deprecated(forRemoval = true, since = "TODO"), if applicable.evalto ease future introduction of Content Security Policy (CSP) directives (see documentation).Desired reviewers
@timja
Before the changes are marked as
ready-for-merge:Maintainer checklist
upgrade-guide-neededlabel is set and there is a Proposed upgrade guidelines section in the pull request title (see example).lts-candidateto be considered.