Skip to content

Commit 724fff0

Browse files
committed
Fixed popup issue
1 parent b821c50 commit 724fff0

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/main/java/gwt/material/design/addins/client/popupmenu/MaterialPopupMenu.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ public class MaterialPopupMenu extends UnorderedList implements JsLoader, HasSel
5757
private String id;
5858
private Object selected;
5959
private boolean autoClose = true;
60-
private boolean autoFocus = false;
6160

6261
public MaterialPopupMenu() {
6362
id = DOM.createUniqueId();
@@ -74,8 +73,10 @@ protected void onLoad() {
7473
@Override
7574
public void load() {
7675
$(this).attr("tabindex", "0");
77-
$(this).on("blur", e -> {
78-
if (autoClose) {
76+
77+
$(window()).off().on("mouseup", e -> {
78+
boolean closest = $(e.target).closest("#" + id).length() == 0;
79+
if (autoClose && closest) {
7980
close();
8081
}
8182
return true;
@@ -191,7 +192,7 @@ public HandlerRegistration addSelectionHandler(SelectionHandler<Element> selecti
191192
@Override
192193
public void open() {
193194
setVisible(true);
194-
if (autoFocus) Scheduler.get().scheduleDeferred(() -> setFocus(true));
195+
Scheduler.get().scheduleDeferred(() -> setFocus(true));
195196

196197
// Check if dropdown is out of the container (Left)
197198
if ($(this).width() + $(this).offset().left > body().width()) {
@@ -219,14 +220,6 @@ public void setSelected(Object selected) {
219220
this.selected = selected;
220221
}
221222

222-
public boolean isAutoFocus() {
223-
return autoFocus;
224-
}
225-
226-
public void setAutoFocus(boolean autoFocus) {
227-
this.autoFocus = autoFocus;
228-
}
229-
230223
@Override
231224
public HandlerRegistration addCloseHandler(CloseHandler<MaterialPopupMenu> closeHandler) {
232225
return addHandler(new CloseHandler<MaterialPopupMenu>() {

0 commit comments

Comments
 (0)