diff --git a/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/main/java/com/vaadin/flow/component/textfield/TextArea.java b/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/main/java/com/vaadin/flow/component/textfield/TextArea.java index 79ab46482f6..2b014bfd73a 100644 --- a/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/main/java/com/vaadin/flow/component/textfield/TextArea.java +++ b/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/main/java/com/vaadin/flow/component/textfield/TextArea.java @@ -399,6 +399,59 @@ public String getPattern() { return getElement().getProperty("pattern"); } + /** + * The minimum number of rows to show. + * + * @return the minimum number of rows + */ + public int getMinRows() { + return getElement().getProperty("minRows", 2); + } + + /** + * Sets the minimum number of rows to show. Default is two rows. + * + * @param minRows + * the minimum number of rows to show + */ + public void setMinRows(int minRows) { + getElement().setProperty("minRows", minRows); + } + + /** + * Maximum number of rows to expand to before the component starts + * scrolling. + * + * @return the maximum number of rows, or {@code null} if the maximum has + * not been set + */ + public Integer getMaxRows() { + String maxRows = getElement().getProperty("maxRows"); + if (maxRows != null && !maxRows.isEmpty()) { + return Integer.parseInt(maxRows); + } + + return null; + } + + /** + * Sets the maximum number of rows to expand to before the component starts + * scrolling. This effectively sets a max-height on the {@code input-field} + * part. By default, the value is {@code null}, which means the component + * grows with the content without constraints. + * + * @param maxRows + * the maximum number of rows, or {@code null} to remove the + * maximum + */ + public void setMaxRows(Integer maxRows) { + if (maxRows != null) { + getElement().setProperty("maxRows", maxRows); + } else { + getElement().removeProperty("maxRows"); + } + } + @Override public String getEmptyValue() { return ""; diff --git a/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/test/java/com/vaadin/flow/component/textfield/tests/TextAreaTest.java b/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/test/java/com/vaadin/flow/component/textfield/tests/TextAreaTest.java index ea2f67a9e76..ac5204eb286 100644 --- a/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/test/java/com/vaadin/flow/component/textfield/tests/TextAreaTest.java +++ b/vaadin-text-field-flow-parent/vaadin-text-field-flow/src/test/java/com/vaadin/flow/component/textfield/tests/TextAreaTest.java @@ -215,4 +215,41 @@ public void implementsInputField() { Assert.assertTrue( field instanceof InputField, String>); } + + @Test + public void getMinRows_defaultValue() { + TextArea field = new TextArea(); + + Assert.assertEquals(2, field.getMinRows()); + } + + @Test + public void setMinRows() { + TextArea field = new TextArea(); + field.setMinRows(5); + + Assert.assertEquals(5, field.getMinRows()); + Assert.assertEquals(5, field.getElement().getProperty("minRows", 0)); + } + + @Test + public void getMaxRows_defaultValue() { + TextArea field = new TextArea(); + + Assert.assertNull(field.getMaxRows()); + } + + @Test + public void setMaxRows() { + TextArea field = new TextArea(); + field.setMaxRows(5); + + Assert.assertEquals(5, (int) field.getMaxRows()); + Assert.assertEquals(5, field.getElement().getProperty("maxRows", 0)); + + field.setMaxRows(null); + + Assert.assertNull(field.getMaxRows()); + Assert.assertNull(field.getElement().getProperty("maxRows")); + } }