diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt index 052d822..45ea830 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/AutocompleteTextField.kt @@ -3,6 +3,7 @@ package net.codinux.banking.ui.forms import androidx.compose.foundation.ScrollState import androidx.compose.foundation.clickable import androidx.compose.foundation.layout.* +import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.verticalScroll import androidx.compose.material.CircularProgressIndicator import androidx.compose.material.Divider @@ -30,6 +31,7 @@ fun AutocompleteTextField( label: @Composable () -> Unit = { Text("Search") }, showDividersBetweenItems: Boolean = true, getItemTitle: ((T) -> String)? = null, + keyboardOptions: KeyboardOptions = KeyboardOptions.Default, fetchSuggestions: suspend (query: String) -> List = { emptyList() }, suggestionContent: @Composable (T) -> Unit ) { @@ -71,6 +73,7 @@ fun AutocompleteTextField( .onGloballyPositioned { textFieldSize = it.size.toSize() }, + keyboardOptions = keyboardOptions, trailingIcon = { if (isLoading) { CircularProgressIndicator( diff --git a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt index 0a3ea2b..8465c41 100644 --- a/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt +++ b/composeApp/src/commonMain/kotlin/net/codinux/banking/ui/forms/OutlinedTextField.kt @@ -8,13 +8,16 @@ import androidx.compose.material.MaterialTheme import androidx.compose.material.TextFieldDefaults import androidx.compose.runtime.Composable import androidx.compose.runtime.remember +import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Shape import androidx.compose.ui.input.key.* import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.input.ImeAction import androidx.compose.ui.text.input.VisualTransformation import net.codinux.banking.ui.config.Colors +@OptIn(ExperimentalComposeUiApi::class) @Composable fun OutlinedTextField( value: String, @@ -47,7 +50,7 @@ fun OutlinedTextField( androidx.compose.material.OutlinedTextField( value = value, onValueChange = onValueChange, - modifier = modifier.onKeyEvent { event -> + modifier = modifier.onKeyEvent { event -> // onKeyEvent only handle input on hardware keyboards if (onEnterPressed != null && event.type == KeyEventType.KeyUp && (event.key == Key.Enter || event.key == Key.NumPadEnter)) { onEnterPressed() true @@ -64,8 +67,8 @@ fun OutlinedTextField( trailingIcon = trailingIcon, isError = isError, visualTransformation = visualTransformation, - keyboardOptions = keyboardOptions, - keyboardActions = keyboardActions, + keyboardOptions = if (onEnterPressed != null) keyboardOptions.copy(imeAction = ImeAction.Done) else keyboardOptions, + keyboardActions = if (onEnterPressed != null) KeyboardActions(onDone = { onEnterPressed.invoke() }) else keyboardActions, // onKeyEvent { } only handles input on hardware keyboards, therefore we have also have to overwrite onDone for IME / soft keyboards singleLine = singleLine, maxLines = maxLines, minLines = minLines,