Skip to content

MultiSelectListBox filter does not work correctly #7543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
tbee opened this issue May 28, 2025 · 0 comments
Open

MultiSelectListBox filter does not work correctly #7543

tbee opened this issue May 28, 2025 · 0 comments

Comments

@tbee
Copy link

tbee commented May 28, 2025

Description

When a row is selected and a filter is active, then when the filter is cleared the selection stays on the presentation index, not the data model index.

Show all:
Image

Apply filter and select 3rd row:
Image

Clear filter, 3rd row (not the item) stays selected:
Image

Expected outcome

The selection should keep the object selected, not the displayed row.

Minimal reproducible example

@Route("/test")
public class TestView extends VerticalLayout {

    public TestView() {
        TextField textField = new TextField();
        textField.setClearButtonVisible(true);
        textField.setValueChangeMode(ValueChangeMode.EAGER);
        add(textField);

        MultiSelectListBox<String> listBox = new MultiSelectListBox<>();
        listBox.setItems("One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine", "Ten");
        listBox.setSelectionPreservationMode(SelectionPreservationMode.PRESERVE_EXISTING);
        add(listBox);

        ListBoxListDataView<String> listDataView = listBox.getListDataView();
        textField.addValueChangeListener(e -> listDataView.setFilter((SerializablePredicate<String>) s -> {
            String filterContent = textField.getValue().toLowerCase();
            return filterContent.isEmpty() || s.toLowerCase().contains(filterContent);
        }));
    }
}

Steps to reproduce

  1. Open the view
  2. Type "i" in the text field
  3. Select "Six" in the listbox
  4. Press the clear button in the textfield

Environment

Vaadin version(s): 24.7.5
OS: Windows

Browsers

Chrome

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

No branches or pull requests

2 participants