Skip to content

Commit

Permalink
Fixed popup issue
Browse files Browse the repository at this point in the history
  • Loading branch information
kevzlou7979 committed Mar 24, 2023
1 parent b821c50 commit 724fff0
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -191,7 +192,7 @@ public HandlerRegistration addSelectionHandler(SelectionHandler<Element> 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()) {
Expand Down Expand Up @@ -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<MaterialPopupMenu> closeHandler) {
return addHandler(new CloseHandler<MaterialPopupMenu>() {
Expand Down

0 comments on commit 724fff0

Please sign in to comment.