Skip to content

Commit fa584e1

Browse files
authored
fix: set viewport-fit=cover to enable CSS env() variables in PWAs (#20836)
Using env() variables in PWAs requires viewport-fit=cover to be set in the <meta name="viewport">. Without this setting, some parts of such components as app-layout get cut off on iOS devices. Adding viewport-fit follows MDN's documentation about env() variables and helps fix such issues . Fixes vaadin/web-components#8449
1 parent 61f75cb commit fa584e1

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

‎flow-server/src/main/java/com/vaadin/flow/component/page/Viewport.java‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
/**
2626
* Defines a viewport tag that will be added to the HTML of the host page of a
2727
* UI class. If no viewport tag has been defined, a default of
28-
* <code>width=device-width, initial-scale=1.0</code> is used.
28+
* <code>width=device-width, initial-scale=1.0, viewport-fit=cover</code> is
29+
* used.
2930
*
3031
* @author Vaadin Ltd
3132
* @since 1.0
@@ -42,20 +43,20 @@
4243
* <p>
4344
* Recommended for a Responsive Web Design.
4445
*/
45-
String DEFAULT = "width=device-width, initial-scale=1.0";
46+
String DEFAULT = "width=device-width, initial-scale=1.0, viewport-fit=cover";
4647

4748
/**
4849
* Sets the viewport to the height of the device rather than the rendered
4950
* space.
5051
*/
51-
String DEVICE_HEIGHT = "height=device-height, initial-scale=1.0";
52+
String DEVICE_HEIGHT = "height=device-height, initial-scale=1.0, viewport-fit=cover";
5253

5354
/**
5455
* Sets the viewport at the width and height of the device. The device-width
5556
* and device-height properties are translated to 100vw and 100vh
5657
* respectively.
5758
*/
58-
String DEVICE_DIMENSIONS = "width=device-width, height=device-height, initial-scale=1.0";
59+
String DEVICE_DIMENSIONS = "width=device-width, height=device-height, initial-scale=1.0, viewport-fit=cover";
5960

6061
/**
6162
* Gets the viewport tag content.

‎flow-tests/test-ccdm/src/test/java/com/vaadin/flow/ccdmtest/IndexHtmlRequestHandlerIT.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void should_add_appShellAnnotations() {
5353
By.cssSelector("meta[name=viewport]"));
5454
Assert.assertNotNull(metaViewPort);
5555
Assert.assertEquals(
56-
"width=device-width, height=device-height, initial-scale=1.0",
56+
"width=device-width, height=device-height, initial-scale=1.0, viewport-fit=cover",
5757
metaViewPort.getAttribute("content"));
5858
}
5959

0 commit comments

Comments
 (0)