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

Dialog opened from a Dialog fires OpenedChangeEvent multiple times #5103

Closed
glebfox opened this issue May 30, 2023 · 1 comment · Fixed by vaadin/web-components#5995
Closed

Comments

@glebfox
Copy link

glebfox commented May 30, 2023

Description

When a dialog is opened from another dialog, it fires OpenedChangeEvent multiple times.

Expected outcome

OpenedChangeEvent is fired once even if a dialog is opened from another dialog.

Minimal reproducible example

import com.example.application.views.MainLayout;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import com.vaadin.flow.router.PageTitle;
import com.vaadin.flow.router.Route;
import com.vaadin.flow.router.RouteAlias;

@PageTitle("Sandbox")
@Route(value = "sandbox", layout = MainLayout.class)
@RouteAlias(value = "", layout = MainLayout.class)
public class SandboxView extends HorizontalLayout {

    public SandboxView() {
        setMargin(true);

        Button openDialogBtn = new Button("Open a dialog", this::openDialog);

        add(openDialogBtn);
    }

    private void openDialog(ClickEvent<Button> __) {
        Dialog dialog = new Dialog();

        VerticalLayout layout = new VerticalLayout();
        dialog.add(layout);

        Button openDialogBtn = new Button("Open a dialog", this::openDialog);
        layout.add(openDialogBtn);

        dialog.addOpenedChangeListener(openedChangeEvent -> {
            if (openedChangeEvent.isOpened()) {
                layout.add(new Label("OpenedChangeEvent"));
            }
        });

        dialog.open();
    }
}

Steps to reproduce

  1. Create a view using snippet above
  2. Click Open a dialog - OpenedChangeEvent is fired once
Screenshot 2023-05-30 at 18 15 31
  1. Click Open a dialog in a dialog - OpenedChangeEvent is fired multiple times
Screenshot 2023-05-30 at 18 15 35

Environment

Vaadin version(s): 24.0.5
OS: MacOS 13.1, Windows 10
Browser: Chrome Version 113.0.5672.126 (Official Build) (x86_64), Safari Version 16.2 (18614.3.7.1.5), FireFox 113.0.2 (64-bit)

Browsers

Chrome, Firefox, Safari

@sissbruecker
Copy link
Contributor

This is might be due to the second dialog being added as a child of the first dialog, and then being moved into the overlay of the first dialog, which causes it to briefly disconnect and then reconnect to the DOM. Dialogs close when being disconnected from the DOM, and reopen when being reconnected. All of those would trigger respective events: first opened from being added to the dialog, then closed from being removed from the dialog, then opened again from being added to the overlay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment