Hide the keyboard when a text field is submitted
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c745f97309
commit
6769463408
1 file changed
+7
-1
@@ -43,6 +43,7 @@ import androidx.compose.ui.geometry.Size
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.SolidColor
|
||||
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.style.TextAlign
|
||||
@@ -278,6 +279,11 @@ fun TextInput(
|
||||
val c = MusyxTheme.colors
|
||||
val shape = RoundedCornerShape(MusyxTheme.radius.pill)
|
||||
var focused by remember { mutableStateOf(false) }
|
||||
val keyboard = LocalSoftwareKeyboardController.current
|
||||
val submit = {
|
||||
keyboard?.hide()
|
||||
onSubmit()
|
||||
}
|
||||
BasicTextField(
|
||||
value = value,
|
||||
onValueChange = onChange,
|
||||
@@ -289,7 +295,7 @@ fun TextInput(
|
||||
keyboardType = if (secret) KeyboardType.Password else KeyboardType.Text,
|
||||
imeAction = imeAction,
|
||||
),
|
||||
keyboardActions = KeyboardActions(onDone = { onSubmit() }, onSearch = { onSubmit() }, onGo = { onSubmit() }),
|
||||
keyboardActions = KeyboardActions(onDone = { submit() }, onSearch = { submit() }, onGo = { submit() }),
|
||||
modifier = modifier.onFocusChanged { focused = it.isFocused },
|
||||
decorationBox = { field ->
|
||||
Box(
|
||||
|
||||
Reference in new issue
Block a user