Hey I have this TextField which has autocomplete u...
# compose
j
Hey I have this TextField which has autocomplete using ExposedDropDownMenu (code in thread), but when a DropDownItem is shown, I can't press the delete button anymore to delete text. Maybe because the dropdown is focused?
Copy code
@Composable
fun SubjectField(
    subject: TextFieldValue,
    onSubjectChange: (TextFieldValue) -> Unit,
    isError: Boolean,
    suggestions: List<String>
) {
    var expandSuggestions by remember { mutableStateOf(false) }
    ExposedDropdownMenuBox(expanded = expandSuggestions, onExpandedChange = { expandSuggestions = it }) {
        ErrorOutlinedTextField(
            modifier = Modifier.menuAnchor(),
            value = subject,
            onValueChange = { onSubjectChange(it); expandSuggestions = true },
            label = { Text(stringResource(R.string.subject)) },
            leadingIcon = { Icon(rememberTypeSpecimen(), contentDescription = null) },
            singleLine = true,
            errorDisplayDelay = 150.milliseconds,
            displayError = isError && subject.text.isBlank()
        )
        ExposedDropdownMenu(
            expanded = suggestions.isNotEmpty() && subject.text.isNotBlank() && expandSuggestions,
            onDismissRequest = { expandSuggestions = false }
        ) {
            suggestions.forEach {
                DropdownMenuItem(
                    text = { Text(it) },
                    onClick = {
                        onSubjectChange(TextFieldValue(it, TextRange(it.length))); expandSuggestions =
                        false
                    },
                    contentPadding = ExposedDropdownMenuDefaults.ItemContentPadding
                )
            }
        }
    }
}