|
19 | 19 |
|
20 | 20 | import com.vaadin.flow.dom.Element;
|
21 | 21 | import com.vaadin.flow.dom.ElementConstants;
|
| 22 | +import com.vaadin.flow.server.Constants; |
22 | 23 |
|
23 | 24 | /**
|
24 | 25 | * Any component implementing this interface supports setting the size of the
|
@@ -47,6 +48,7 @@ public interface HasSize extends HasElement {
|
47 | 48 | */
|
48 | 49 | default void setWidth(String width) {
|
49 | 50 | getElement().getStyle().setWidth(width);
|
| 51 | + getElement().removeAttribute(Constants.ATTRIBUTE_WIDTH_FULL); |
50 | 52 | }
|
51 | 53 |
|
52 | 54 | /**
|
@@ -194,6 +196,7 @@ default Optional<Unit> getWidthUnit() {
|
194 | 196 | */
|
195 | 197 | default void setHeight(String height) {
|
196 | 198 | getElement().getStyle().setHeight(height);
|
| 199 | + getElement().removeAttribute(Constants.ATTRIBUTE_HEIGHT_FULL); |
197 | 200 | }
|
198 | 201 |
|
199 | 202 | /**
|
@@ -332,30 +335,71 @@ default Optional<Unit> getHeightUnit() {
|
332 | 335 | * This is just a convenience method which delegates its call to the
|
333 | 336 | * {@link #setWidth(String)} and {@link #setHeight(String)} methods with
|
334 | 337 | * {@literal "100%"} as the argument value
|
| 338 | + * <p> |
| 339 | + * When adding full-size components as a child of a Vaadin layout component |
| 340 | + * that is based on CSS Flexbox, such as HorizontalLayout or VerticalLayout, |
| 341 | + * this can result in unexpected behavior. For example, other components |
| 342 | + * with a fixed size may shrink to allow the full-size component to take up |
| 343 | + * as much space as possible, or the full-size component may cause the |
| 344 | + * layout to overflow. To improve this, you can enable the |
| 345 | + * {@code com.vaadin.experimental.layoutComponentImprovements} feature flag |
| 346 | + * to effectively make full-size components take up the <b>remaining</b> |
| 347 | + * space in the layout, rather than explicitly using 100% size of the |
| 348 | + * layout. This applies additional CSS styles that allow the component to |
| 349 | + * shrink below 100% if there are other components with fixed or relative |
| 350 | + * sizes in the layout. |
335 | 351 | */
|
336 | 352 | default void setSizeFull() {
|
337 |
| - setWidth("100%"); |
338 |
| - setHeight("100%"); |
| 353 | + setWidthFull(); |
| 354 | + setHeightFull(); |
339 | 355 | }
|
340 | 356 |
|
341 | 357 | /**
|
342 | 358 | * Sets the width of the component to "100%".
|
343 | 359 | * <p>
|
344 | 360 | * This is just a convenience method which delegates its call to the
|
345 |
| - * {@link #setWidth(String)} with {@literal "100%"} as the argument value |
| 361 | + * {@link #setWidth(String)} with {@literal "100%"} as the argument value. |
| 362 | + * <p> |
| 363 | + * When adding full-size components as a child of a Vaadin layout component |
| 364 | + * that is based on CSS Flexbox, such as HorizontalLayout or VerticalLayout, |
| 365 | + * this can result in unexpected behavior. For example, other components |
| 366 | + * with a fixed size may shrink to allow the full-size component to take up |
| 367 | + * as much space as possible, or the full-size component may cause the |
| 368 | + * layout to overflow. To improve this, you can enable the |
| 369 | + * {@code com.vaadin.experimental.layoutComponentImprovements} feature flag |
| 370 | + * to effectively make full-size components take up the <b>remaining</b> |
| 371 | + * space in the layout, rather than explicitly using 100% size of the |
| 372 | + * layout. This applies additional CSS styles that allow the component to |
| 373 | + * shrink below 100% if there are other components with fixed or relative |
| 374 | + * sizes in the layout. |
346 | 375 | */
|
347 | 376 | default void setWidthFull() {
|
348 | 377 | setWidth("100%");
|
| 378 | + getElement().setAttribute(Constants.ATTRIBUTE_WIDTH_FULL, true); |
349 | 379 | }
|
350 | 380 |
|
351 | 381 | /**
|
352 | 382 | * Sets the height of the component to "100%".
|
353 | 383 | * <p>
|
354 | 384 | * This is just a convenience method which delegates its call to the
|
355 | 385 | * {@link #setHeight(String)} with {@literal "100%"} as the argument value
|
| 386 | + * <p> |
| 387 | + * When adding full-size components as a child of a Vaadin layout component |
| 388 | + * that is based on CSS Flexbox, such as HorizontalLayout or VerticalLayout, |
| 389 | + * this can result in unexpected behavior. For example, other components |
| 390 | + * with a fixed size may shrink to allow the full-size component to take up |
| 391 | + * as much space as possible, or the full-size component may cause the |
| 392 | + * layout to overflow. To improve this, you can enable the |
| 393 | + * {@code com.vaadin.experimental.layoutComponentImprovements} feature flag |
| 394 | + * to effectively make full-size components take up the <b>remaining</b> |
| 395 | + * space in the layout, rather than explicitly using 100% size of the |
| 396 | + * layout. This applies additional CSS styles that allow the component to |
| 397 | + * shrink below 100% if there are other components with fixed or relative |
| 398 | + * sizes in the layout. |
356 | 399 | */
|
357 | 400 | default void setHeightFull() {
|
358 | 401 | setHeight("100%");
|
| 402 | + getElement().setAttribute(Constants.ATTRIBUTE_HEIGHT_FULL, true); |
359 | 403 | }
|
360 | 404 |
|
361 | 405 | /**
|
|
0 commit comments