-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial implementation of VaadinFormLayout (#2068)
Closes #1932
- Loading branch information
Showing
10 changed files
with
909 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...t/flow-components-demo/src/main/java/com/vaadin/flow/demo/views/VaadinFormLayoutView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2000-2017 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.demo.views; | ||
|
||
import com.vaadin.flow.demo.ComponentDemo; | ||
import com.vaadin.flow.html.Div; | ||
import com.vaadin.flow.html.H3; | ||
import com.vaadin.ui.VaadinFormLayout; | ||
import com.vaadin.ui.VaadinFormLayout.ResponsiveStep; | ||
import com.vaadin.ui.VaadinFormLayout.VaadinFormItem; | ||
import com.vaadin.ui.VaadinTextField; | ||
|
||
/** | ||
* Demo view for {@link VaadinFormLayout}. | ||
* | ||
* @author Vaadin Ltd | ||
*/ | ||
@ComponentDemo(name = "Vaadin Form Layout", href = "vaadin-form-layout") | ||
public class VaadinFormLayoutView extends DemoView { | ||
|
||
@Override | ||
void initView() { | ||
// @formatter:off | ||
// begin-source-example | ||
// source-example-heading: A form layout with custom responsive layouting | ||
VaadinFormLayout nameLayout = new VaadinFormLayout(); | ||
|
||
VaadinTextField titleField = new VaadinTextField() | ||
.setLabel("Title") | ||
.setPlaceholder("Sir"); | ||
VaadinTextField firstNameField = new VaadinTextField() | ||
.setLabel("First name") | ||
.setPlaceholder("John"); | ||
VaadinTextField lastNameField = new VaadinTextField() | ||
.setLabel("Last name") | ||
.setPlaceholder("Doe"); | ||
|
||
nameLayout.add(titleField, firstNameField, lastNameField); | ||
|
||
nameLayout.setResponsiveSteps( | ||
new ResponsiveStep("0", 1), | ||
new ResponsiveStep("20em", 2), | ||
new ResponsiveStep("22em", 3)); | ||
// end-source-example | ||
// @formatter:on | ||
|
||
// begin-source-example | ||
// source-example-heading: A form layout with fields wrapped in form items | ||
VaadinFormLayout layoutWithFormItems = new VaadinFormLayout(); | ||
|
||
VaadinFormItem firstItem = new VaadinFormItem( | ||
new VaadinTextField().setPlaceholder("John")); | ||
VaadinFormItem secondItem = new VaadinFormItem( | ||
new VaadinTextField().setPlaceholder("Doe")); | ||
|
||
Div firstItemLabelComponent = new Div(); | ||
firstItemLabelComponent.setText("First name"); | ||
|
||
Div secondItemLabelComponent = new Div(); | ||
secondItemLabelComponent.setText("Last name"); | ||
|
||
firstItem.addToLabel(firstItemLabelComponent); | ||
secondItem.addToLabel(secondItemLabelComponent); | ||
|
||
layoutWithFormItems.add(firstItem, secondItem); | ||
// end-source-example | ||
|
||
add(new H3("A form layout with custom responsive layouting"), | ||
nameLayout); | ||
add(new H3("A form layout with fields wrapped in form items"), | ||
layoutWithFormItems); | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...ent/flow-components-demo/src/test/java/com/vaadin/flow/demo/views/VaadinFormLayoutIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright 2000-2017 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.demo.views; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openqa.selenium.Dimension; | ||
import org.openqa.selenium.WebElement; | ||
|
||
import com.vaadin.flow.demo.AbstractChromeTest; | ||
import com.vaadin.testbench.By; | ||
|
||
/** | ||
* Integration tests for the {@link VaadinFormLayoutView}. | ||
*/ | ||
public class VaadinFormLayoutIT extends AbstractChromeTest { | ||
|
||
private WebElement layout; | ||
|
||
@Before | ||
public void init() { | ||
open(); | ||
waitForElementPresent(By.tagName("main-layout")); | ||
layout = findElement(By.tagName("main-layout")); | ||
Assert.assertTrue(isElementPresent(By.tagName("vaadin-form-layout"))); | ||
} | ||
|
||
@Test | ||
public void custom_responsive_layouting() { | ||
WebElement firstLayout = layout | ||
.findElement(By.tagName("vaadin-form-layout")); | ||
List<WebElement> textFields = firstLayout | ||
.findElements(By.tagName("vaadin-text-field")); | ||
Assert.assertEquals(3, textFields.size()); | ||
|
||
getDriver().manage().window().setSize(new Dimension(1000, 1000)); | ||
|
||
// 3 columns, all should be horizontally aligned (tolerance of 2 pixels | ||
// given) | ||
Assert.assertTrue("All 3 columns should be horizontally aligned", | ||
Math.abs(textFields.get(2).getLocation().getY() | ||
- textFields.get(1).getLocation().getY()) < 2); | ||
Assert.assertTrue(Math.abs(textFields.get(1).getLocation().getY() | ||
- textFields.get(0).getLocation().getY()) < 2); | ||
|
||
getDriver().manage().window().setSize(new Dimension(450, 620)); | ||
|
||
// window resized, should be in 2 column mode, last textfield below | ||
// other two | ||
Assert.assertTrue( | ||
"Layout should be in 2 column mode, last field should be below the first two", | ||
textFields.get(2).getLocation().getY() > textFields | ||
.get(1).getLocation().getY()); | ||
Assert.assertTrue(textFields.get(2).getLocation().getY() > textFields | ||
.get(0).getLocation().getY()); | ||
|
||
getDriver().manage().window().setSize(new Dimension(400, 620)); | ||
|
||
// resized to 1 column mode, fields should be arranged below one another | ||
Assert.assertTrue( | ||
"Layout should be in 1 column mode, all fields should be below one another", | ||
textFields.get(2).getLocation().getY() > textFields | ||
.get(1).getLocation().getY()); | ||
Assert.assertTrue(textFields.get(1).getLocation().getY() > textFields | ||
.get(0).getLocation().getY()); | ||
} | ||
|
||
@Override | ||
protected String getTestPath() { | ||
return "/vaadin-form-layout"; | ||
} | ||
} |
Oops, something went wrong.