vaadin-component-factory / multi-combo-box-flow

https://incubator.app.fi/multi-combo-box-flow-demo/
Apache License 2.0
3 stars 1 forks source link

Opened changed listener is fired on attach #19

Open stefanuebe opened 3 years ago

stefanuebe commented 3 years ago

Description

As the title says, the opened changed listener is directly fired when the MCB is attached to its parent. The event says, that it is closed, so in theory it is not providing false information regarding the state, but the expectation here is, that since the MCB has not been opened yet before, the event itself is simply misfired here.

Sample to show use case

@Route(value = "multi-combobox-view", layout = MainLayout.class) public class MultiComboboxView extends HorizontalLayout { public MultiComboboxView(SamplePersonService service) { MultiComboBox1 box = new MultiComboBox1<>(); box.addAttachListener(event -> { System.out.println("on attach"); }); System.out.println("add listener 1"); box.addOpenedChangeListener(event -> { System.out.println("event 1"); }); System.out.println("set items"); box.setItems(service.list()); System.out.println("add listener 2"); box.addOpenedChangeListener(event -> { System.out.println("event 2"); });

    System.out.println("add");
    add(box);
    box.addOpenedChangeListener(event -> {
        System.out.println("event 3");
    });
}

// needed to have the opened change listener available to the outside
public class MultiComboBox1<T> extends MultiComboBox<T> {
    @Override
    public Registration addOpenedChangeListener(ComponentEventListener<OpenedChangeEvent<MultiComboBox<T>>> listener) {
        return super.addOpenedChangeListener(listener);
    }
}

}