Skip to content

Commit

Permalink
feat: add convenience method for setting label width (#6398)
Browse files Browse the repository at this point in the history
* add convenience method for setting label width

* add test

* apply suggestion

Co-authored-by: Sascha Ißbrücker <[email protected]>

* Add corresponding getter

* Update FormLayout.java

---------

Co-authored-by: Sascha Ißbrücker <[email protected]>
  • Loading branch information
FrediWa and sissbruecker authored Jul 4, 2024
1 parent fea4ce1 commit 5c802f1
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=
* "https://vaadin.com/docs/latest/components/form-layout#label-position">Label position</a>
*/
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 <a href=
* "https://vaadin.com/docs/latest/components/form-layout#label-position">Label position</a>
*/
public String getLabelWidth() {
return this.getStyle().get("--vaadin-form-item-label-width");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

0 comments on commit 5c802f1

Please sign in to comment.