hanki.dev

Compose ExposedDropdownMenuBox: problems with TalkBack

Jetpack Compose has ExposedDropdownMenuBox which is for creating dropdown menus. I couldn't get TalkBack to work with it properly so I had to revert to using regular Box. So if you have your dropdown menu done with ExposedDropdownMenuBox but can't get TalkBack working properly, all you gotta do is:

Then if you have problems with the dropdown menu width you can fix it using this trick (from SO):

  1. Add the variable to keep textField width:
var textFieldSize by remember { mutableStateOf(Size.Zero) }
  1. Set the value in the onGloballyPositioned of TextField
onGloballyPositioned { coordinates ->
   textFieldSize = coordinates.size.toSize()
}
  1. Read the value in ExposedDropdownMenu
ExposedDropdownMenu(
    expanded = expanded,
    onDismissRequest = { expanded = false },
    modifier = Modifier
        .background(Color.White)
        .width(with(LocalDensity.current) { textFieldSize.width.toDp() })
)

✌🏼 Like my content? Subscribe via RSS feed.