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

Add API to set position to a dialog and sync values on user interaction #1173

Open
DiegoCardoso opened this issue Feb 19, 2020 · 8 comments
Open
Labels
enhancement New feature or request vaadin-dialog

Comments

@DiegoCardoso
Copy link
Contributor

After (https://github.com/vaadin/vaadin-dialog/issues/145), flow component should add API to allow setting the overlay position.

Also, the component should sync the position value, at least in two cases:

  • setDraggable is set to true and a dialog is dragged by the user
  • setResizable is set to true and a dialog is resized by the user (the reason is that when a resize happens, the dialog defines the top/left position).
@web-padawan
Copy link
Member

web-padawan commented Feb 22, 2020

See also vaadin/vaadin-dialog-flow#138 for a feature request for similar API that also includes an example code.

@mlopezFC
Copy link
Contributor

If there is someone who cannot wait until the "set a specific position for a dialog" feature is released, here is a workaround:

@Route
@PWA(name = "My Application", shortName = "My Application")
@CssImport(value = "./styles/custom-styles.css", id = "custom-dialog-styles", themeFor = "vaadin-*-overlay")
public class MainView extends VerticalLayout {

    public MainView() {
    	Dialog d = new Dialog(new TextField("Text field", "Text Field"));
    	d.getElement().setAttribute("theme", "dialog-top-left");
    	
        Button button = new Button("Click me",
                event ->  {
                	d.open();
        });
        add(button);
    }
}

And custom-styles.css:

:host([theme~="dialog-top-left"]) [part~="overlay"]
{
    align-self: flex-start;
    position: absolute;
    top: 0px;
    left: 0px;
}

@SebastianKuehnau
Copy link

SebastianKuehnau commented Jul 20, 2020

Another workaround could be

getElement().executeJs("this.$.overlay.$.overlay.style[$0]=$1", "align-self", "flex-start");
getElement().executeJs("this.$.overlay.$.overlay.style[$0]=$1", "position", "absolute");
getElement().executeJs("this.$.overlay.$.overlay.style[$0]=$1", "left", "<your x value in pixel>");
getElement().executeJs("this.$.overlay.$.overlay.style[$0]=$1", "top", <your y value in pixel>);

to change the position directly.

@AndrasJanurik
Copy link

@SebastianKuehnau Thanks, nice workaround!

Do you have an idea for a getter as well?
I tried this:

getElement().executeJs("return this.$.overlay.$.overlay.style['left']");

but since executeJs runs in a separate thread and returns only a PendingJavaScriptResult the result value cannot simply be returned from a getter.

@SebastianKuehnau
Copy link

SebastianKuehnau commented Aug 17, 2020

please try this:

public void getPosition(SerializableConsumer<Position> consumer) {
  getElement().executeJs("return [this.$.overlay.$.overlay.style['top'], this.$.overlay.$.overlay.style['left']]")
    .then(String.class, s -> {
          String[] split = StringUtils.split(s, ',');
          if (split.length == 2 && split[0] != null && split[1] != null) {
              Position position = new Position(split[0], split[1]);
              consumer.accept(position);
          }
    });
}

@HHA-Abacus
Copy link

HHA-Abacus commented Sep 16, 2020

Even if the workaround can help, this feature would be much more comfortable to use with an API.
Looking forward :)

@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-dialog-flow Oct 6, 2020
@vaadin-bot vaadin-bot transferred this issue from vaadin/vaadin-dialog May 19, 2021
@vaadin-bot vaadin-bot transferred this issue from vaadin/web-components May 21, 2021
@vaadin-bot vaadin-bot added enhancement New feature or request vaadin-dialog labels May 21, 2021
@simasch
Copy link

simasch commented Mar 24, 2023

What is the state of this issue? When will Dialog positioning be possible?

@scrmtrey91
Copy link

scrmtrey91 commented Apr 11, 2023

Any news ? Need for vaadin 23+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request vaadin-dialog
Projects
None yet
Development

No branches or pull requests

9 participants