Dropdown doesn't display when switching from setEnabled(false) to setEnabled(true)
paodb opened this issue · 2 comments
If I initialize the combobox with setEnabled(false), when trying to switch to setEnabled(true), the dropdown is not displaying. Here's an example to reproduce the issue:
Button toggleButton = new Button("Toggle combobox status");
MultiselectComboBox<User> combobox = new MultiselectComboBox<User>("Combo");
toggleButton.addClickListener(e -> {
combobox.setEnabled(!combobox.isEnabled());
});
combobox.setEnabled(false);
combobox.setItems(List.of(new User("1", "Jane"), new User("2", "John")));
combobox.setItemLabelGenerator(User::getName);
add(toggleButton, combobox);
Vaadin version: 23.0.1
Component version: 4.0.0-rc2
This issue is also relevant for me and i hope this will fix very soon.
I have an Solution that works for me. The trick is that the webcomponent calls Client Callable when it is Ready.
First i set the enabled state to true. This is needed that the Component renders correct. Wehn the Component is ready in Dom i set the Enabeld state.
`public class MultiselectComboBoxExt extends MultiselectComboBox implements HasLabel {
private boolean enabledState;
private boolean attached = false;
public MultiselectComboBoxExt() {
super.setEnabled(true);
}
@OverRide
public void setEnabled(boolean enabled) {
if (!attached) {
enabledState = enabled;
} else {
super.setEnabled(enabled);
}
}
@ClientCallable
private void notifyReady() {
this.getElement().executeJs("$0.$connector.initDataConnector()", new Serializable[0]);
attached = true;
setEnabled(enabledState);
}`