Skip to content

Commit 291e6f5

Browse files
committed
Improve the previous commit and test it manually
1 parent 4034a60 commit 291e6f5

File tree

1 file changed

+6
-1
lines changed
  • compose-multiplatform-material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/ext

1 file changed

+6
-1
lines changed

compose-multiplatform-material3/src/jsMain/kotlin/com/huanshankeji/compose/material3/ext/TextField.js.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ import com.varabyte.kobweb.compose.ui.attrsModifier
2121
import org.jetbrains.compose.web.attributes.AttrsScope
2222
import org.w3c.dom.HTMLElement
2323

24+
private fun inputType(singleLine: Boolean, lines: Int) =
25+
// This is consistent with the `androidx.compose.material3` text field behavior.
26+
if (singleLine || lines == 1) null else TextareaInputType
27+
2428
private fun Modifier.toTextFieldAttrs(
2529
onValueChange: (String) -> Unit, keyboardOptions: KeyboardOptions, keyboardActions: KeyboardActions,
2630
): AttrsScope<HTMLElement>.() -> Unit =
@@ -83,6 +87,7 @@ actual fun TextField(
8387
rows = if (singleLine) null else lines,
8488
placeholder = placeholder,
8589
readOnly = readOnly.isTrueOrNull(),
90+
type = inputType(singleLine, lines),
8691

8792
attrs = modifier.toTextFieldAttrs(onValueChange, keyboardOptions, keyboardActions),
8893
content = TextFieldContent(value, leadingIcon, trailingIcon)
@@ -123,7 +128,7 @@ actual fun OutlinedTextField(
123128
rows = if (singleLine) null else lines,
124129
placeholder = placeholder,
125130
readOnly = readOnly.isTrueOrNull(),
126-
type = if (singleLine) null else TextareaInputType,
131+
type = inputType(singleLine, lines),
127132

128133
attrs = modifier.toTextFieldAttrs(onValueChange, keyboardOptions, keyboardActions),
129134
content = TextFieldContent(value, leadingIcon, trailingIcon)

0 commit comments

Comments
 (0)