Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Nested dialogs closeEvent not working as expected #80

Closed
AlexRoig opened this issue Jun 17, 2018 · 5 comments
Closed

Nested dialogs closeEvent not working as expected #80

AlexRoig opened this issue Jun 17, 2018 · 5 comments
Assignees

Comments

@AlexRoig
Copy link

Hi,

When I create a dialog in a dialog the event propagation of close event is not working as intended.
Here are the behaviours observed when the second (nested) dialog is opened on top:
a) When clicking outside the dialog to dismiss it, the server side events registered in Dialog#addDialogCloseActionListener() are executed as expected but the dialog is not closed. You can keep clicking outside and the dialog will not disappear and the events will be executed at each click.
b) When pressing ESC key to close the dialog the events, we have the same behaviour as a).
c) When adding a button to the second dialog and adding a clickListener to the button that calls the Dialog#close() method, then the events registered on Dialog#addDialogCloseActionListener() are not executed.

I'll try to provide a minimum code to test the functionality. Currently tested with RC5

Thx,
Alex

@denis-anisimov denis-anisimov added this to the 1.0 Maintenance milestone Jun 18, 2018
@denis-anisimov denis-anisimov self-assigned this Aug 1, 2018
@denis-anisimov
Copy link

Thank you for reporting but I cannot reproduce the issue with the latest dialog release.

I'm using the code below

Dialog dialog = new Dialog();
        dialog.add(new Text("xxxxxx"));

        Dialog subDialog = new Dialog();
        subDialog.add(new Text("uuuu"));
        dialog.add(subDialog);

        dialog.open();

        NativeButton button = new NativeButton("Open subdialog",
                event -> subDialog.open());
        dialog.add(button);

Also the second dialog is closed if it's not added into the first dialog (the line dialog.add(subDialog); is commented out).

Another thing to note is: it looks like you are describing the client side behavior only which means this is the web component behavior, not the server component. It might be that this behavior is fixed in the final version.

I'm closing the ticket since I cannot reproduce it based on the description. If you have a code which shows how to reproduce it please reopen and add this code.

@AlexRoig
Copy link
Author

AlexRoig commented Aug 2, 2018

Hi Denis,

Managed to figure out what was going on with this. Taking your example, I added at the bottom this couple lines to listen for the close event:

    subDialog.addDialogCloseActionListener(l -> System.out.println("Closing sub-dialog"));
    dialog.addDialogCloseActionListener(l -> System.out.println("Closing main dialog"));

Thea addDialogCloseActionListener prevents the default action to close the dialog (when clicking outside). In order to get it working i need to add specifically a call for Dialog::close.

    subDialog.addDialogCloseActionListener(l -> {
        System.out.println("Closing sub-dialog");
        subDialog.close();
    });
    dialog.addDialogCloseActionListener(l -> {
        System.out.println("Closing main dialog");
        dialog.close();
    });

Another issue that can easily be reproduced, would be adding these couple lines of code at the end of your example:

    //Add a button with a close action in subDialog();
    subDialog.add(new NativeButton("Close Dialog", event -> subDialog.close()));
    //Print a message when closing the dialog
    subDialog.addDialogCloseActionListener(l -> System.out.println("Closing sub-dialog"));

When clicking the button "Close Dialog", the message is not printed. And I'd say that this is the most critical part of the issue. That you cannot update the contents of the main dialog after the sub-dialog is closed by the user action pressing a button.
Moreover, with this code, the subdialog will not close when clicking outside of the dialog area but the event will be fired.

@denis-anisimov
Copy link

Alright, now I see what's the problem. It's addDialogCloseActionListener method which adds some JS on the client side and this causes issues.

@denis-anisimov denis-anisimov reopened this Aug 3, 2018
@denis-anisimov
Copy link

denis-anisimov commented Aug 3, 2018

This ticket is strongly connected with #68.
In fact the fix which I'm going to do should fix this issue as well.

There will be a test for the scenario from this ticket.
I'm not closing this as a duplicate since the scenario is not the same but it will be fixed by the same PR.

As a final note I have to say that the name for the addDialogCloseActionListener is bad and confusing. I will update javadocs for it. Unfortunately it's too late to change the method name.

Please note that if you use the addDialogCloseActionListener method then it's your responsibility to close the dialog. The dialog won't be closed for you automatically if you click outside it. You should call close method on the server side in the listener implementation. Otherwise you are using the method in a wrong way.
I you still need automatic closing of the dialog and be notified when it happens then you should use addOpenedChangeListener which is called whenever opened property value is updated (meaning also when it becomes false which means the dialog is closed).

@denis-anisimov
Copy link

The PR for this : #91.

I will close this ticket since it will be fixed along with #68 though the latter ticket is no a duplicate.

Feel free reopen if you still think it's not fixed with the mentioned PR.
Thanks.

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

No branches or pull requests

2 participants