vaadin-component-factory / tooltip

Java API for vcf-tooltip
https://incubator.app.fi/tooltip-demo/tooltip
Apache License 2.0
3 stars 2 forks source link

Tooltip is not working in a Dialog when the dialog is reopened #13

Open jcgueriaud1 opened 3 years ago

jcgueriaud1 commented 3 years ago

Step to reproduce: In the demo

jcgueriaud1 commented 3 years ago

From the other ticket. Here is an example to reproduce:

@Route(value = "Future", layout = MainLayout.class)
@RouteAlias(value = "/Future", layout = MainLayout.class)
public class FutureView extends VerticalLayout {

    BaseForm form;
    public FutureView() {
                this.setSizeFull();
        form = new BaseForm();
        form.open();

        Button btn = new Button("Open form");
        btn.addClickListener(e->form.open());

        add(btn,form);
    }
}

class BaseForm extends Dialog {
    Tooltip tooltip;
    TextField text;

    public BaseForm() {
        text= new TextField();
        text.setReadOnly(true);

        tooltip= new Tooltip();
        tooltip.attachToComponent(text);
        tooltip.add(new Span("Some"));
        add(text,tooltip);
    }
}
AntKerf commented 3 years ago

As a temporary solution, using a script in the BaseForm.java class helped me. if you do not open the form in the constructor, the script will not work :(

text.setId("target");
tooltip.setId("tooltip");
UI.getCurrent().getPage().executeJs("document.getElementById('target').onmouseover = function(){"
                + "document.getElementById('tooltip').removeAttribute('hidden');"
                + "};"
                + "document.getElementById('target').onmouseleave = function(){"
                + "document.getElementById('tooltip').setAttribute('hidden', 'true');"
                + "};"
                + "window.onload = function(){"
                + "document.getElementById('overlay').removeAttribute('opened');"
                + "document.getElementById('overlay').setAttribute('closing', 'true');"
                + "};");