feat: add setFocusSelectedItem to ComboBox#9239
Open
DiegoCardoso wants to merge 1 commit into
Open
Conversation
457506d to
f7b15a7
Compare
43ca860 to
fea69b9
Compare
Adds an opt-in API on ComboBox<T> that scrolls the dropdown to the currently selected item when it opens, restoring the pre-#6055 behavior behind a flag. comboBox.setFocusSelectedItem(true); Off by default. The listener for `vaadin-combo-box-dropdown-opened` runs server-side, resolves the selected item's index via the data view (in-memory or lazy with ItemIndexProvider), and calls scrollToIndex on the web component. No @ClientCallable or connector code is needed: PR #11552's scrollToIndex queues the call when the overlay is loading, and the connector refactor (separate PR) means the controller's pendingRequests map is now coherent across close/reopen. The listener is a silent no-op when: - no value is currently selected, - a filter is active (the user is narrowing down — don't override their navigation by jumping to the previously selected item), - the lazy data view has no ItemIndexProvider configured, or - the resolved index cannot be determined. In-memory data works out of the box (no ItemIndexProvider needed). Tests: - ComboBoxTest: defaults-to-false and getter/setter round-trip. - ComboBoxFocusSelectedItemIT: 13 tests covering the happy path, reopen, value change, filter behavior, missing-provider fallback, in-memory case, runtime toggle, detach+reattach, and toggle-off regression guard. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
f7b15a7 to
396fc99
Compare
|
vursen
reviewed
May 14, 2026
| } else { | ||
| index = getLazyDataView().getItemIndex(getValue()).orElse(null); | ||
| } | ||
| } catch (UnsupportedOperationException e) { |
Contributor
There was a problem hiding this comment.
Why does the exception need to be suppressed?
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.



Restores the pre-vaadin/web-components#6055 behavior of focusing the currently selected item when the combo-box dropdown opens, behind an opt-in flag.
Off by default. When enabled, opening the dropdown scrolls to the currently selected item. The implementation listens for
vaadin-combo-box-dropdown-opened, resolves the selected item's index via the data view (in-memory or lazy withItemIndexProvider), and callsscrollToIndexon the web component (added in vaadin/web-components#11552).The listener is a silent no-op when:
ItemIndexProviderconfigured, orIn-memory data works out of the box (no
ItemIndexProviderneeded).Tests:
ComboBoxTest: defaults-to-false and getter/setter round-trip.ComboBoxFocusSelectedItemIT: 13 tests covering the happy path, reopen, value change, filter behavior (active and cleared), missing-provider fallback, in-memory case, runtime toggle, detach + reattach, and toggle-off regression guard.Note
Stacked on #9238. Will retarget to
mainonce that merges.Part of vaadin/web-components#6061
🤖 Generated with Claude Code