diff --git a/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/main/java/com/vaadin/flow/component/formlayout/FormLayout.java b/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/main/java/com/vaadin/flow/component/formlayout/FormLayout.java index 4c4ad043938..104ca0d9fbb 100644 --- a/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/main/java/com/vaadin/flow/component/formlayout/FormLayout.java +++ b/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/main/java/com/vaadin/flow/component/formlayout/FormLayout.java @@ -449,4 +449,28 @@ public FormItem addFormItem(Component field, Component label) { add(formItem); return formItem; } + + /** + * Set the width of side-positioned label. + * + * @param width + * the value and CSS unit as a string + * @see Label position + */ + public void setLabelWidth(String width) { + this.getStyle().set("--vaadin-form-item-label-width", width); + } + + /** + * Get the width of side-positioned label. + * + * @return + * the value and CSS unit as a string + * @see Label position + */ + public String getLabelWidth() { + return this.getStyle().get("--vaadin-form-item-label-width"); + } } diff --git a/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/test/java/com/vaadin/flow/component/formlayout/tests/FormLayoutTest.java b/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/test/java/com/vaadin/flow/component/formlayout/tests/FormLayoutTest.java index eeca1bcd76b..2b7a4db76d4 100644 --- a/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/test/java/com/vaadin/flow/component/formlayout/tests/FormLayoutTest.java +++ b/vaadin-form-layout-flow-parent/vaadin-form-layout-flow/src/test/java/com/vaadin/flow/component/formlayout/tests/FormLayoutTest.java @@ -99,4 +99,13 @@ public void setResponsiveSteps_getResponsiveSteps() { ResponsiveStep.LabelsPosition.TOP)); Assert.assertEquals(3, formLayout.getResponsiveSteps().size()); } + + @Test + public void setLabelWidth_getLabelWidth() { + FormLayout formLayout = new FormLayout(); + formLayout.setLabelWidth("2em"); + + String appliedWidth = formLayout.getLabelWidth(); + Assert.assertEquals(appliedWidth, "2em"); + } }