Christoph Wiesner
03/28/2023, 8:24 AMmenuAnchor()
which should actually handle that afaik)
Has anyone overcome that problem?val options = listOf("Option 1", "Option 2", "Option 3", "Option 4", "Option 5")
var exp by remember { mutableStateOf(false) }
var selectedOption by remember { mutableStateOf("") }
ExposedDropdownMenuBox(expanded = exp, onExpandedChange = { exp = !exp }) {
TextField(
value = selectedOption,
onValueChange = { selectedOption = it
if (options.any { it.contains(selectedOption, ignoreCase = true) })
exp = true },
label = { Text("Label") },
modifier = Modifier.menuAnchor()
)
// filter options based on text field value (i.e. crude autocomplete)
val filterOpts = options.filter { it.contains(selectedOption, ignoreCase = true) }
if (filterOpts.isNotEmpty()) {
ExposedDropdownMenu(expanded = exp, onDismissRequest = { exp = false }) {
filterOpts.forEach { option ->
DropdownMenuItem(
onClick = {
selectedOption = option
exp = false
},
text = { Text(text = option) }
)
}
}
}
}