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

feat: add position API to Dialog #6782

Merged
merged 6 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ private void createResizableDraggableDialog() {
dialog.setDraggable(true);
dialog.setWidth("200px");
dialog.setHeight("200px");
dialog.setTop("50px");
dialog.setLeft("50px");
sissbruecker marked this conversation as resolved.
Show resolved Hide resolved

Div message = new Div();
message.setId("dialog-resizable-draggable-message");
Expand All @@ -214,6 +216,13 @@ private void createResizableDraggableDialog() {
e -> dialog.open());
openDialog.setId("dialog-resizable-draggable-open-button");

NativeButton setPosition = new NativeButton("set custom position",
e -> {
dialog.setTop("100px");
dialog.setLeft("200px");
});
setPosition.setId("dialog-resizable-draggable-set-position-button");

NativeButton sizeRestrictions = new NativeButton(
"set resizing restrictions", e -> {
dialog.setMinWidth("175px");
Expand All @@ -223,7 +232,7 @@ private void createResizableDraggableDialog() {
});
sizeRestrictions.setId("dialog-resizing-restrictions-button");

add(openDialog, message, sizeRestrictions);
add(openDialog, setPosition, message, sizeRestrictions);
}

private void changeDialogDimensions() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ public void openDialogAddComponentAtIndex() {
assertButtonText(1);
}

@Test
sissbruecker marked this conversation as resolved.
Show resolved Hide resolved
public void setDialogPosition() {
findElement(By.id("dialog-resizable-draggable-set-position-button"))
.click();
findElement(By.id("dialog-resizable-draggable-open-button")).click();

TestBenchElement dialogOverlay = $("*").id("overlay");
TestBenchElement overlay = dialogOverlay.$("*").id("overlay");
Assert.assertEquals("100px", overlay.getCssValue("top"));
Assert.assertEquals("200px", overlay.getCssValue("left"));
}

private void assertButtonText(int index) {
Assert.assertEquals("Button Text is not correct", "Added Button",
findElements(By.cssSelector(DIALOG_OVERLAY_TAG)).get(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,51 @@ public DialogCloseActionEvent(Dialog source, boolean fromClient) {
}
}

/**
* Gets the top position of the overlay.
*
* @return the top position of the overlay
*/
public String getTop() {
return getElement().getProperty("top");
}

/**
* Sets the top position of the overlay. If a unitless number is provided,
* pixels are assumed.
* <p>
* Note that the overlay top edge may not be the same as the viewport top
* edge (e.g. the "Lumo" theme defines some spacing to prevent the overlay
* from stretching all the way to the top of the viewport).
*
* @param top
* the top position of the overlay
*/
public void setTop(String top) {
getElement().setProperty("top", top);
}

/**
* Gets the left position of the overlay.
*
* @return the left position of the overlay
*/
public String getLeft() {
return getElement().getProperty("left");
}

/**
* Sets the distance of the overlay from the left of its container. If a
* unitless number is provided, pixels are assumed.
* <p>
* Note that the overlay left edge may not be the same as the viewport left
* edge (e.g. the "Lumo" theme defines some spacing to prevent the overlay
* from stretching all the way to the left of the viewport).
*/
public void setLeft(String left) {
sissbruecker marked this conversation as resolved.
Show resolved Hide resolved
getElement().setProperty("left", left);
}

/**
* `resize` event is sent when the user finishes resizing the overlay.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ public void open_close_notAutoAttachedInBeforeClientResponse() {
Assert.assertNull(dialog.getElement().getParent());
}

@Test
public void position_setTopLeft_positionIsDefined() {
Dialog dialog = new Dialog();
dialog.setTop("10px");
dialog.setLeft("20px");

Assert.assertEquals("10px", dialog.getTop());
Assert.assertEquals("20px", dialog.getLeft());
}

private void fakeClientResponse() {
ui.getInternals().getStateTree().runExecutionsBeforeClientResponse();
ui.getInternals().getStateTree().collectChanges(ignore -> {
Expand Down