diff --git a/src/main/java/gwt/material/design/addins/client/popupmenu/MaterialPopupMenu.java b/src/main/java/gwt/material/design/addins/client/popupmenu/MaterialPopupMenu.java index 0398df97..c7b5a6a8 100644 --- a/src/main/java/gwt/material/design/addins/client/popupmenu/MaterialPopupMenu.java +++ b/src/main/java/gwt/material/design/addins/client/popupmenu/MaterialPopupMenu.java @@ -57,7 +57,6 @@ public class MaterialPopupMenu extends UnorderedList implements JsLoader, HasSel private String id; private Object selected; private boolean autoClose = true; - private boolean autoFocus = false; public MaterialPopupMenu() { id = DOM.createUniqueId(); @@ -74,8 +73,10 @@ protected void onLoad() { @Override public void load() { $(this).attr("tabindex", "0"); - $(this).on("blur", e -> { - if (autoClose) { + + $(window()).off().on("mouseup", e -> { + boolean closest = $(e.target).closest("#" + id).length() == 0; + if (autoClose && closest) { close(); } return true; @@ -191,7 +192,7 @@ public HandlerRegistration addSelectionHandler(SelectionHandler selecti @Override public void open() { setVisible(true); - if (autoFocus) Scheduler.get().scheduleDeferred(() -> setFocus(true)); + Scheduler.get().scheduleDeferred(() -> setFocus(true)); // Check if dropdown is out of the container (Left) if ($(this).width() + $(this).offset().left > body().width()) { @@ -219,14 +220,6 @@ public void setSelected(Object selected) { this.selected = selected; } - public boolean isAutoFocus() { - return autoFocus; - } - - public void setAutoFocus(boolean autoFocus) { - this.autoFocus = autoFocus; - } - @Override public HandlerRegistration addCloseHandler(CloseHandler closeHandler) { return addHandler(new CloseHandler() {