flow-components
flow-components copied to clipboard
ComboBox is missing an addOpenedChangeListener
trafficstars
Describe your motivation
The ComboBox component is missing an addOpenedChangeListener.
Describe the solution you'd like
An addOpenedChangeListener in ComboBox similar to how it is present in DatePicker
Describe alternatives you've considered
comboBox.getElement().addPropertyChangeListener("opened", "opened-changed", event -> {
// do something
});
Additional context
No response
This is a low hanging fruit as the component fires the low level event already, you can thus use Element API to observe it
combobox.getElement().addEventListener("opened-changed", e -> {
Notification.show(e.getEventData().toJson());
}).addEventData("event.detail");
Excellent work @TatuLund , thank you. I've built on your example code a bit:
public class MyComboBox<T> extends ComboBox<T> {
/**
* @param listener invoked when the dropdown overlay is opened or closed. Receives true if the dropdown is opened, false if it is closed.
* @return the registration.
*/
@NonNull
public Registration addOpenedChangeListener(@NonNull SerializableConsumer<Boolean> listener) {
return getElement().addEventListener("opened-changed", e -> {
final boolean opened = e.getEventData().getObject("event.detail").getBoolean("value");
listener.accept(opened);
}).addEventData("event.detail");
}
}