viritin / flow-viritin

Viritin inspired project for Vaadin Flow
Other
43 stars 15 forks source link

Geolocation can not pierce the modal dialog veil #47

Closed mvysny closed 8 months ago

mvysny commented 8 months ago

Consider the following example:

@Route("")
public class MainView extends VerticalLayout {

    public MainView() {
        final Dialog dlg = new Dialog();
        dlg.setModal(true);
        final Button button = new Button("Get location");
        button.addClickListener(e2 -> {
            button.setEnabled(false);
            Geolocation.getCurrentPosition(e -> System.out.println("Got location " + e.getCoords()), e -> System.out.println("ERROR: " + e));
        });
        dlg.add(button);
        add(new Button("dlg", e -> dlg.open()));
    }
}

Viritin fires the geoupdate CustomEvent on the UI but unfortunately the event is ignored by Flow because there's a modal Dialog open. Perhaps the fix would be to fire events on the modal Dialog itself if there is a modal element open.

mvysny commented 8 months ago

Yup, modifying Geolocation a bit resolves the issue:

    private static Geolocation checkPosition(UI ui, UpdateListener listener, ErrorListener errorListener, GeolocationOptions options, boolean get) {
        Geolocation geolocation = new Geolocation();
        final Component modal = ui.getInternals().getActiveModalComponent();
        geolocation.ui = modal == null ? ui : modal;

Then replace all ui.getElement() with geolocation.ui.getElement()

mstahv commented 8 months ago

Fixed (or workaround, probably a not perfect solutions still...) in https://github.com/viritin/flow-viritin/commit/7cff9b226a42b8393b9fd7316a53e0cd8495ed45

Version cut, but oss sonatype seems to be pending...