Skip to content

Commit c289bed

Browse files
committed
Add a TextField in the demo and remove an inconsistent placeholder argument in TextField's implementation
It turns out that the `placeholder` argument supported only by desktop/Android and the `helperText` supported only by KMDC are not the same thing. The placeholder is shown in the text field when there is no text, while the helper text is shown below the text field when it's in focus.
1 parent 2b03871 commit c289bed

File tree

4 files changed

+10
-4
lines changed
  • compose-multiplatform-material/src
    • commonMain/kotlin/com/huanshankeji/compose/material
    • jsMain/kotlin/com/huanshankeji/compose/material
    • jvmMain/kotlin/com/huanshankeji/compose/material
  • demo/src/commonMain/kotlin/com/huanshankeji/compose/material/demo

4 files changed

+10
-4
lines changed

compose-multiplatform-material/src/commonMain/kotlin/com/huanshankeji/compose/material/TextField.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ expect fun TextField(
1313
modifierOrAttrs: ModifierOrAttrs<TextFieldElement> = null,
1414
enabled: Boolean = true,
1515
label: String? = null,
16+
/*
1617
placeholder: String? = null,
18+
helperText: String? = null,
19+
*/
1720
leadingIcon: @Composable (() -> Unit)? = null,
1821
trailingIcon: @Composable (() -> Unit)? = null,
1922
)

compose-multiplatform-material/src/jsMain/kotlin/com/huanshankeji/compose/material/TextField.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ actual fun TextField(
1515
modifierOrAttrs: ModifierOrAttrs<TextFieldElement>,
1616
enabled: Boolean,
1717
label: String?,
18-
placeholder: String?,
1918
leadingIcon: @Composable (() -> Unit)?,
2019
trailingIcon: @Composable (() -> Unit)?,
2120
) =
@@ -26,7 +25,6 @@ actual fun TextField(
2625
},
2726
disabled = !enabled,
2827
label = label,
29-
helperText = placeholder,
3028
leadingIcon = leadingIcon?.let { { it() } },
3129
trailingIcon = trailingIcon?.let { { it() } }
3230
)

compose-multiplatform-material/src/jvmMain/kotlin/com/huanshankeji/compose/material/TextField.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ actual fun TextField(
1414
modifierOrAttrs: ModifierOrAttrs<TextFieldElement>,
1515
enabled: Boolean,
1616
label: String?,
17-
placeholder: String?,
1817
leadingIcon: @Composable (() -> Unit)?,
1918
trailingIcon: @Composable (() -> Unit)?,
2019
) =
@@ -24,7 +23,6 @@ actual fun TextField(
2423
modifierOrAttrs.toModifier(),
2524
enabled = enabled,
2625
label = label?.let { { Text(it) } },
27-
placeholder = placeholder?.let { { Text(it) } },
2826
leadingIcon = leadingIcon,
2927
trailingIcon = trailingIcon
3028
)

demo/src/commonMain/kotlin/com/huanshankeji/compose/material/demo/App.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ fun App() {
105105
DemoSquare(rgbaColor(0xFFU, 0U, 0U, 0x80U))
106106
DemoSquare(rgbaColor(0xFFU, 0U, 0U, 0.5F))
107107
}
108+
109+
var text by remember { mutableStateOf("") }
110+
TextField(
111+
text, { text = it },
112+
label = "Demo text field",
113+
leadingIcon = { Icon(MaterialIcons.Add, null) },
114+
trailingIcon = { Icon(MaterialIcons.Menu, null) })
108115
}
109116
}
110117
}

0 commit comments

Comments
 (0)