Skip to content

Commit ff7ce6a

Browse files
authored
feat: add wrap API to HorizontalLayout/VerticalLayout (#6839)
1 parent e6ebd25 commit ff7ce6a

File tree

2 files changed

+37
-0
lines changed
  • vaadin-ordered-layout-flow-parent/vaadin-ordered-layout-flow/src

2 files changed

+37
-0
lines changed

vaadin-ordered-layout-flow-parent/vaadin-ordered-layout-flow/src/main/java/com/vaadin/flow/component/orderedlayout/ThemableLayout.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,38 @@ default boolean isSpacing() {
105105
return getThemeList().contains("spacing");
106106
}
107107

108+
/**
109+
* Sets whether items should wrap to new lines/columns when they exceed the
110+
* layout's boundaries. When enabled, items maintain their size and create
111+
* new rows or columns as needed, depending on the layout's orientation.
112+
* <p>
113+
* When disabled, items will be compressed to fit within a single
114+
* row/column.
115+
*
116+
* @param wrap
117+
* true to enable wrapping, false to force items into a single
118+
* row/column
119+
*/
120+
default void setWrap(boolean wrap) {
121+
getThemeList().set("wrap", wrap);
122+
}
123+
124+
/**
125+
* Gets whether items will wrap to new lines/columns when they exceed the
126+
* layout's boundaries.
127+
* <p>
128+
* When wrapping is enabled, items maintain their defined dimensions by
129+
* creating new rows or columns as needed. When disabled, items may be
130+
* compressed to fit within the available space.
131+
*
132+
* @return true if wrapping is enabled, false if items are forced into a
133+
* single row/column
134+
* @see #setWrap(boolean)
135+
*/
136+
default boolean isWrap() {
137+
return getThemeList().contains("wrap");
138+
}
139+
108140
/**
109141
* Gets the set of the theme names applied to the corresponding element in
110142
* {@code theme} attribute. The set returned can be modified to add or

vaadin-ordered-layout-flow-parent/vaadin-ordered-layout-flow/src/test/java/com/vaadin/flow/component/orderedlayout/tests/ThemableLayoutTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public void checkSpacing() {
6464
checkThemeToggling("spacing", layout::isSpacing, layout::setSpacing);
6565
}
6666

67+
@Test
68+
public void checkWrap() {
69+
checkThemeToggling("wrap", layout::isWrap, layout::setWrap);
70+
}
71+
6772
private void checkThemeToggling(String themeName,
6873
Supplier<Boolean> themeGetter, Consumer<Boolean> themeSetter) {
6974
assertFalse(String.format(

0 commit comments

Comments
 (0)