Skip to content

feat: add focusSelectedItem flag to combo-box#9194

Draft
DiegoCardoso wants to merge 1 commit intomainfrom
feat/combo-box/focus-selected-item
Draft

feat: add focusSelectedItem flag to combo-box#9194
DiegoCardoso wants to merge 1 commit intomainfrom
feat/combo-box/focus-selected-item

Conversation

@DiegoCardoso
Copy link
Copy Markdown
Contributor

@DiegoCardoso DiegoCardoso commented Apr 24, 2026

Summary

Adds ComboBox.setFocusSelectedItem(boolean) / isFocusSelectedItem() and an @ClientCallable resolveSelectedItemIndex() that returns an authoritative flat index for the current value via ItemIndexProvider (lazy) or the list data view (in-memory), with silent fallback to the web-component's best-effort behavior when neither is available.

The connector (comboBoxConnector.js) wires a vaadin-combo-box-dropdown-opened listener with token-based "switch" cancellation for overlapping filter changes / pending fetches, plus a filter-changed re-resolve and a close-side needsDataCommunicatorReset arm. The latter prevents a stuck loading state when the scroller re-requests the same viewport range the server last sent on reopen.

Fixes vaadin/web-components#6061.

Depends on

Cannot merge until both of these land in `vaadin/web-components`:

Test plan

  • `ComboBoxFocusSelectedItemIT` — 23/23 pass (A regression guards incl. `A6_reopen_loadingResolves_andReFocusesSelected`, B filter interactions, C edge cases)
  • `ComboBoxClientSideDataRangeIT` — 4/4 pass
  • `ComponentRendererIT` — 5/5 pass
  • Run against a local web-components checkout with both dependency PRs applied (user-side check)

🤖 Generated with Claude Code

comboBox.addEventListener('vaadin-combo-box-dropdown-opened', resolveFocusSelectedItem);
// `_onOpened` doesn't re-run on filter change, so the web component can't
// re-arm its own `__shouldFocusSelectedItem` latch — re-resolve ourselves.
comboBox.addEventListener('filter-changed', () => {
Copy link
Copy Markdown
Contributor

@sissbruecker sissbruecker Apr 27, 2026

Choose a reason for hiding this comment

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

I think I would prefer if it would not do that. If I enter a new filter, I likely want to select a different item. Based on the filtered results I then want to scan the list from top to bottom. Then it doesn't sound helpful that it scrolls down somewhere to the current selection.

Adds ComboBox.setFocusSelectedItem(boolean) / isFocusSelectedItem() and an
@ClientCallable resolveSelectedItemIndex() that returns an authoritative
flat index for the current value via ItemIndexProvider (lazy data) or the
list data view (in-memory). Falls back silently to the web-component's
best-effort behavior when neither is available.

The connector wires a vaadin-combo-box-dropdown-opened listener with
token-based "switch" cancellation for overlapping filter changes / pending
fetches, plus a filter-changed re-resolve and a close-side
needsDataCommunicatorReset arm — the latter prevents a stuck loading
state when the scroller re-requests the same viewport range the server
last sent on reopen.

Includes ComboBoxFocusSelectedItemPage + ComboBoxFocusSelectedItemIT
(23 tests covering regression guards, filter interactions,
domain-type / binder / detach-reattach / throwing-ItemIndexProvider
edge cases, plus an A6 regression guard for the reopen stuck-loading
bug).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@DiegoCardoso DiegoCardoso force-pushed the feat/combo-box/focus-selected-item branch from cfa1c60 to 81e662d Compare April 27, 2026 16:56
@sonarqubecloud
Copy link
Copy Markdown

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.

[combo-box] Add API to re-enable focusing the selected item

2 participants