Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no straightforward solution to hide the popup when leaving the page with browser-back #15

Open
thomasharre opened this issue Jan 28, 2022 · 2 comments

Comments

@thomasharre
Copy link

thomasharre commented Jan 28, 2022

If a Popup is open and the user uses the browser-back (or forward) he navigates to the previous page but the Popup stays visible.
Ideally the PopUp would automatically disappear when the Component it is for is detached.

Initially I thought I would solve this by adding a BeforeLeaveObserver, so something like

public class MyPopup extends Popup implements BeforeLeaveObserver {

  public void beforeLeave(BeforeLeaveEvent event) {
    if (isOpened()) {
      hide();
    }
  }

}

But that did not work.

Markus then found this solution that works:

public class MyPopup extends Popup implements BeforeLeaveObserver {

  public void beforeLeave(BeforeLeaveEvent event) {
    if (isOpened()) {
      final BeforeLeaveEvent.ContinueNavigationAction postponedEvent = event.postpone();
      hideWithResult().then(result -> postponedEvent.proceed());
    }
  }

  private PendingJavaScriptResult hideWithResult() {
    return getElement().callJsFunction("hide");
  }

}

So could the popup be changed, to either disappear automatically or to always disappear when hide is called?

@TatuLund
Copy link
Contributor

TatuLund commented Feb 2, 2022

The popup is implemented using vaadin-overlay component. And I am now contemplating what is the correct action here.

One approach is to conclude that the solution above is the correct one and should be used in with Popup, and if necessary with other components utilizing vaadin-overlay (e.g. Notification, Tooltip, Dialog, ...)

Or should there be some change done in vaadin-overlay itself (then all the components using it, would inherit the fix, not just the Popup)

Or should all the components utilizing vaadin-overlay be fixed individually as per need arises.

@TatuLund
Copy link
Contributor

TatuLund commented Feb 2, 2022

With some research I found that the same problem has been reported with Dialog as well

vaadin/flow-components#1541

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants