Commit f10450b
fix: focus selected item with wrapped in-memory data providers (#9396)
A `ComboBox` with `setFocusSelectedItem(true)` throws a
`ClassCastException` when opening the dropdown if its items come from a
`ListDataProvider` wrapped with `withConvertedFilter(...)`.
`scrollToSelectedItem()` resolved the selected item's index through the
list data view, which casts the provider to `ListDataProvider`. The
wrapper is in-memory but not a `ListDataProvider`, so the cast fails.
```java
ComboBox<String> comboBox = new ComboBox<>();
ListDataProvider<String> dataProvider = DataProvider
.ofCollection(List.of("A", "B", "C", "D"));
comboBox.setItems(dataProvider.withConvertedFilter(
filterText -> item -> item.contains(filterText)));
comboBox.setFocusSelectedItem(true);
comboBox.setValue("C");
comboBox.setOpened(true); // throws ClassCastException
```
`scrollToSelectedItem()` now resolves the index through the generic data
view (`ComboBoxDataView`) for in-memory providers instead of the list
data view. The generic data view reads items from the data communicator
and works for any in-memory provider, wrapped or not, so the list data
view is no longer used for providers that aren't a `ListDataProvider`.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent ab10f50 commit f10450b
2 files changed
Lines changed: 35 additions & 1 deletion
File tree
- vaadin-combo-box-flow-parent/vaadin-combo-box-flow/src
- main/java/com/vaadin/flow/component/combobox
- test/java/com/vaadin/flow/component/combobox
Lines changed: 6 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
422 | 422 | | |
423 | 423 | | |
424 | 424 | | |
425 | | - | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
426 | 431 | | |
427 | 432 | | |
428 | 433 | | |
| |||
Lines changed: 29 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| 33 | + | |
32 | 34 | | |
33 | 35 | | |
34 | 36 | | |
| 37 | + | |
| 38 | + | |
35 | 39 | | |
36 | 40 | | |
37 | 41 | | |
| |||
253 | 257 | | |
254 | 258 | | |
255 | 259 | | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
256 | 285 | | |
257 | 286 | | |
258 | 287 | | |
| |||
0 commit comments