Fixed if a textColor is set, than also unfocused border color is displayed is displayed in this color

This commit is contained in:
dankito 2024-09-06 16:56:16 +02:00
parent 4a180b5970
commit 255cc41dce
2 changed files with 5 additions and 8 deletions

View File

@ -3,9 +3,7 @@ package net.codinux.banking.ui.forms
import androidx.compose.foundation.interaction.MutableInteractionSource import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.text.KeyboardActions import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.LocalTextStyle import androidx.compose.material.*
import androidx.compose.material.MaterialTheme
import androidx.compose.material.TextFieldDefaults
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.ExperimentalComposeUiApi import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
@ -47,6 +45,8 @@ fun OutlinedTextField(
) { ) {
val textFieldColors = TextFieldDefaults.outlinedTextFieldColors( val textFieldColors = TextFieldDefaults.outlinedTextFieldColors(
focusedBorderColor = Colors.CodinuxSecondaryColor, focusedBorderColor = Colors.CodinuxSecondaryColor,
// a workaround: we assume textStyle is set to change text color, so we set unfocusedBorderColor according to it // TODO: fix by passing textColor to OutlinedTextField
unfocusedBorderColor = if (textStyle != LocalTextStyle.current) textStyle.color else MaterialTheme.colors.primary.copy(alpha = ContentAlpha.high),
focusedLabelColor = Colors.CodinuxSecondaryColor // does not work focusedLabelColor = Colors.CodinuxSecondaryColor // does not work
) )

View File

@ -6,7 +6,6 @@ import androidx.compose.runtime.*
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.TextStyle import androidx.compose.ui.text.TextStyle
import net.codinux.banking.ui.config.Colors
@OptIn(ExperimentalMaterialApi::class) @OptIn(ExperimentalMaterialApi::class)
@Composable @Composable
@ -24,7 +23,7 @@ fun <T> Select(
var showDropDownMenu by remember { mutableStateOf(false) } var showDropDownMenu by remember { mutableStateOf(false) }
ExposedDropdownMenuBox(showDropDownMenu, { isExpanded -> showDropDownMenu = isExpanded }, modifier.fillMaxWidth()) { ExposedDropdownMenuBox(showDropDownMenu, { isExpanded -> showDropDownMenu = isExpanded }, modifier.fillMaxWidth()) {
OutlinedTextField( net.codinux.banking.ui.forms.OutlinedTextField(
value = getItemDisplayText(selectedItem), value = getItemDisplayText(selectedItem),
onValueChange = { }, onValueChange = { },
modifier = Modifier.fillMaxWidth(), modifier = Modifier.fillMaxWidth(),
@ -33,9 +32,7 @@ fun <T> Select(
readOnly = true, readOnly = true,
maxLines = 1, maxLines = 1,
trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(showDropDownMenu) }, trailingIcon = { ExposedDropdownMenuDefaults.TrailingIcon(showDropDownMenu) },
leadingIcon = leadingIcon, leadingIcon = leadingIcon
colors = if (textColor == null) TextFieldDefaults.outlinedTextFieldColors()
else TextFieldDefaults.outlinedTextFieldColors(textColor = textColor, unfocusedBorderColor = textColor, unfocusedLabelColor = textColor, placeholderColor = textColor, focusedBorderColor = Colors.CodinuxSecondaryColor)
) )
// due to a bug (still not fixed since 2021) in ExposedDropdownMenu its popup has a maximum width of 800 pixel / 320dp which is too less to fit // due to a bug (still not fixed since 2021) in ExposedDropdownMenu its popup has a maximum width of 800 pixel / 320dp which is too less to fit