Impossible set focus to Component after open non-modal Dialog

B"H

Hi,

Might be a bug.

And might connect the setClose options that act differently on non modal dialogs.



very simple:

dialog.open();

text.focus();



the conclusion is no focus on text. next call can be set as dialog stay open.

text in not part of the dialog.

Is it a bug?

Thanks

I’m not sure if it’s a bug. By default if you open a dialog it will request the focus.

Here is a sample with a workaround:


@Route("dialog")
public class DialogView extends VerticalLayout {

    public DialogView() {
        TextField text = new TextField("Text");
        Button button = new Button("open dialog", e -> {
            Dialog dialog = new Dialog();
            VerticalLayout verticalLayout = new VerticalLayout(new Div(), new Button("close", event -> dialog.close()));
            dialog.add(verticalLayout);
            dialog.setModal(false);
            dialog.open();
            // text.focus(); does not work
            // workaround
            text.getElement().executeJs("setTimeout(function(){$0.focus()},10)", text.getElement());
        });
        add(text,button);
    }

}

Does it help?

B"H

Yes. thats help. thanks