Skip to content

Commit eb27f67

Browse files
committed
Add more KDocs for Modifier.outerPadding about its UI issues when used with the Modifier.fillMax... modifiers
1 parent 53ff09f commit eb27f67

File tree

3 files changed

+49
-2
lines changed

3 files changed

+49
-2
lines changed

common/src/commonMain/kotlin/com/huanshankeji/compose/foundation/layout/ext/InnerPadding.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.ui.unit.dp
66
import com.huanshankeji.compose.foundation.background
77
import com.huanshankeji.compose.foundation.clickable
88
import com.huanshankeji.compose.foundation.layout.PaddingValues
9+
import com.huanshankeji.compose.foundation.layout.padding
910
import com.huanshankeji.compose.ui.Modifier
1011

1112
/**

common/src/commonMain/kotlin/com/huanshankeji/compose/foundation/layout/ext/OuterPadding.kt

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import androidx.compose.ui.unit.Dp
55
import androidx.compose.ui.unit.dp
66
import com.huanshankeji.compose.foundation.background
77
import com.huanshankeji.compose.foundation.clickable
8-
import com.huanshankeji.compose.foundation.layout.PaddingValues
8+
import com.huanshankeji.compose.foundation.layout.*
99
import com.huanshankeji.compose.ui.Modifier
1010

1111
/**
@@ -23,6 +23,52 @@ expect fun Modifier.outerPadding(horizontal: Dp = 0.dp, vertical: Dp = 0.dp): Mo
2323
/**
2424
* This delegates to the CSS `margin` property on JS DOM and adds the padding outside.
2525
* For consistency on different platforms, please use it as the **first** modifier **before** the other modifiers such as [background] and [clickable].
26+
*
27+
* However, as [CSS `box-sizing`](https://developer.mozilla.org/en-US/docs/Web/CSS/box-sizing) doesn't have a `margin-box` value, when this is used with [fillMaxSize]/[fillMaxWidth]/[fillMaxHeight] on JS DOM the visual result may be not what you expect.
28+
* In such a case, either replace it with [fillMaxSizeStretch]/[fillMaxWidthStretch]/[fillMaxHeightStretch] or use [innerPadding] on an outer parent instead.
29+
*
30+
* Copy and render the following code to see the problem yourself:
31+
*
32+
```html
33+
<!DOCTYPE html>
34+
<html>
35+
36+
<head>
37+
<style>
38+
.inner-div {
39+
width: 100%;
40+
height: 64px;
41+
padding: 16px;
42+
margin: 16px;
43+
background: white;
44+
border: 2px solid yellow;
45+
box-sizing: border-box;
46+
}
47+
48+
.outer-div {
49+
background: orange;
50+
border: 2px solid red;
51+
padding: 16px;
52+
}
53+
</style>
54+
</head>
55+
56+
<body>
57+
58+
<h1>box-sizing with margin</h1>
59+
<p>In <code>.inner-div</code>, either remove <code>margin</code> or set <code>width</code> to <code>-webkit-fill-available</code>.
60+
61+
<br>
62+
<div class="outer-div">
63+
<div class="inner-div"></div>
64+
</div>
65+
<div>
66+
67+
</body>
68+
69+
</html>
70+
```
71+
*
2672
* See the KDoc of the [padding] overload with one [Dp] parameter for more information.
2773
* @see innerPadding
2874
*/

common/src/jsMain/kotlin/com/huanshankeji/compose/foundation/layout/ext/Size.js.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import com.varabyte.kobweb.compose.ui.styleModifier
1010
import org.jetbrains.compose.web.css.StyleScope
1111

1212
private const val CSS_STRETCH_VALUE = "stretch" // This does not work on Chrome.
13-
private const val CSS_WEBKIT_STRETCH_VALUE = "-webkit-fill-available"
13+
private const val CSS_WEBKIT_STRETCH_VALUE = "-webkit-fill-available" // This actually works on FireFox too as tested.
1414
private const val CSS_MOZ_STRETCH_VALUE = "-moz-available"
1515
val cssWidthStretchValueBrowserDependent =
1616
when (browser) {

0 commit comments

Comments
 (0)