Skip to content

feat: center focused item in combo-box dropdown#11875

Open
DiegoCardoso wants to merge 2 commits into
mainfrom
feat/combo-box-center-focused-item
Open

feat: center focused item in combo-box dropdown#11875
DiegoCardoso wants to merge 2 commits into
mainfrom
feat/combo-box-center-focused-item

Conversation

@DiegoCardoso
Copy link
Copy Markdown
Contributor

@DiegoCardoso DiegoCardoso commented Jun 1, 2026

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

  • Add an opt-in alignToCenter parameter to the scroller's scrollIntoView. The default bottom alignment used by arrow keys, clicks and filtering is unchanged, so existing callers (including the Flow integration that calls scrollIntoView directly) keep working.
  • __focusIndex sets _focusedIndex before 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.
  • Fix the jump: scrollIntoView returned 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

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.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Jun 1, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant