I ran into an issue today where if I specify a trailing icon for a BasicTextField it forces the height of the field to be increased. Any way to override this setting? As you can see in the image the 555g field is shorter than the Ingredient1 which became taller due to the addition of the trailingIcon.
I've tried to understand what's happening in compose and after digging I came across this code in the Google native TextField.kt
if (trailing != null) {
Box(
modifier = Modifier
.layoutId(LeadingId)
.then(IconDefaultSizeModifier),
contentAlignment = Alignment.Center
) {
trailing()
}
}
So I am inferring from this that IconDefaultSizeModifier
is forcing the minHeight
to be 48.dp
and below is the code that I use to create the BasicTextField
BasicTextField(
value = state,
//... more arguments
decorationBox = @Composable {
TextFieldDefaults.OutlinedTextFieldDecorationBox(
value = textVal,
visualTransformation = VisualTransformation.None,
innerTextField = it,
singleLine = singleLine,
enabled = enabled,
interactionSource = interactionSource,
trailingIcon = trailingIcon,
// keep vertical paddings but change the horizontal
contentPadding = TextFieldDefaults.textFieldWithoutLabelPadding(
top = 10.dp,
bottom = 10.dp,
start = 12.dp,
end = 8.dp
),
container = {}
)
}
)