feat: center focused item in combo-box dropdown#11875
Open
DiegoCardoso wants to merge 2 commits into
Open
Conversation
Programmatically focusing an item (e.g. the selected item when the overlay opens) bottom-aligned it. Center it instead so it is immediately visible wherever it falls in the sort order. Add an opt-in `alignToCenter` parameter to the scroller's `scrollIntoView`; the default bottom alignment used by arrow keys, clicks and filtering is unchanged. `__focusIndex` sets `_focusedIndex` before scrolling so the observer-driven scroll runs first (the property is sync), then centers last so the final position wins. Related to #6061
scrollIntoView re-ran scrollToIndex(firstVisibleIndex) even when the focused row was already visible, snapping an unaligned scrollTop to a row boundary. With the centered focus the scroll is never row-aligned, so the first arrow press moved the whole list. Return early when the target is already fully visible so only the focus ring moves.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



When the combo-box scrolls a focused item into view programmatically — for example the selected item when the overlay opens — it placed the item at the bottom of the dropdown. It is better to show it in the middle, so it is immediately visible wherever it falls in the sort order. This matches the position chosen for the feature in the linked issue.
While adding this, a related scroll glitch became visible: after the viewport is centered, pressing Arrow Up/Down once moved the whole list by a few pixels before settling, instead of just moving the focus ring. The same jump already happened whenever the scroll position was not aligned to a row (e.g. after scrolling with the mouse).
Before
combo-box-before.mp4
After
combo-box-after.mp4
Changes
alignToCenterparameter to the scroller'sscrollIntoView. The default bottom alignment used by arrow keys, clicks and filtering is unchanged, so existing callers (including the Flow integration that callsscrollIntoViewdirectly) keep working.__focusIndexsets_focusedIndexbefore scrolling. Because that property is synchronous, the observer-driven scroll runs first, then the explicit centered scroll runs last and wins — so no extra state is needed to keep the item centered.scrollIntoViewreturned to a row boundary even when the focused row was already fully visible. It now returns early in that case, so only the focus ring moves.Follow-up to #11552, Related to #6061
🤖 Generated with Claude Code