Skip to content

Commit aec2c52

Browse files
committed
1 parent 2ccc40d commit aec2c52

File tree

4 files changed

+258
-117
lines changed

4 files changed

+258
-117
lines changed

docs/components/textfield.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ TextField(
2626
)
2727
```
2828

29+
::: info
30+
This TextField component now also supports the latest state-based version. Please refer to the [State-based](https://developer.android.com/develop/ui/compose/text/user-input?textfield=state-based) documentation for details.
31+
:::
32+
2933
## Input Types
3034

3135
### TextField with Label

docs/zh_CN/components/textfield.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ TextField(
2626
)
2727
```
2828

29+
::: info 信息
30+
此 TextFiled 组件现在也支持最新基于状态的版本,具体请参考 [State-based](https://developer.android.com/develop/ui/compose/text/user-input?textfield=state-based&hl=zh-cn) 文档。
31+
:::
32+
2933
## 输入框类型
3034

3135
### 带标签输入框

example/src/commonMain/kotlin/component/OtherComponent.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import androidx.compose.foundation.layout.width
2323
import androidx.compose.foundation.lazy.LazyListScope
2424
import androidx.compose.foundation.text.KeyboardActions
2525
import androidx.compose.foundation.text.KeyboardOptions
26+
import androidx.compose.foundation.text.input.rememberTextFieldState
2627
import androidx.compose.runtime.getValue
2728
import androidx.compose.runtime.mutableStateOf
2829
import androidx.compose.runtime.remember
@@ -252,6 +253,9 @@ fun LazyListScope.otherComponent(focusManager: FocusManager, padding: PaddingVal
252253

253254
item {
254255
var text1 by remember { mutableStateOf("") }
256+
var text2 by remember { mutableStateOf(TextFieldValue("")) }
257+
val text3 = rememberTextFieldState(initialText = "")
258+
var text4 by remember { mutableStateOf("") }
255259

256260
SmallTitle(text = "TextField")
257261
TextField(
@@ -263,28 +267,28 @@ fun LazyListScope.otherComponent(focusManager: FocusManager, padding: PaddingVal
263267
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
264268
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
265269
)
266-
}
267-
item {
268-
var text2 by remember { mutableStateOf(TextFieldValue("")) }
269-
270270
TextField(
271271
value = text2,
272272
onValueChange = { text2 = it },
273-
label = "Text Field",
273+
label = "With title",
274274
modifier = Modifier
275275
.padding(horizontal = 12.dp)
276276
.padding(bottom = 12.dp),
277277
keyboardActions = KeyboardActions(onDone = { focusManager.clearFocus() }),
278278
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done)
279279
)
280-
}
281-
282-
item {
283-
var text3 by remember { mutableStateOf("") }
284-
285280
TextField(
286-
value = text3,
287-
onValueChange = { text3 = it },
281+
state = text3,
282+
label = "State-based",
283+
modifier = Modifier
284+
.padding(horizontal = 12.dp)
285+
.padding(bottom = 12.dp),
286+
onKeyboardAction = { focusManager.clearFocus() },
287+
keyboardOptions = KeyboardOptions(imeAction = ImeAction.Done),
288+
)
289+
TextField(
290+
value = text4,
291+
onValueChange = { text4 = it },
288292
label = "Placeholder & SingleLine",
289293
useLabelAsPlaceholder = true,
290294
singleLine = true,

0 commit comments

Comments
 (0)