I want to dismiss a popup with an outside click, b...
# compose
p
I want to dismiss a popup with an outside click, but the click doesn’t seem to be consumed by the dismiss action, and is responded to by whatever background item is clicked on. How can I have it so the click just dismisses the popup and nothing else? In the following toy code, my ideal would be for the counter to increment when the popup is not displayed, but not when clicking to dismiss it
Copy code
@Composable
fun PopupTest() {
  val show = remember{ mutableStateOf(false)}
  val ctr = remember{ mutableStateOf(0)}

  Box(
    Modifier
      .fillMaxSize()
      .clickable { ctr.value += 1 }) {
    Button({show.value = !show.value}, Modifier.align(Alignment.TopCenter).offset(y = 20.dp)) {
      Text("Show Popup")
    }
    if (show.value) {
      Popup(alignment = Alignment.Center,
        onDismissRequest = {show.value = false}){
        Text("I am the popup", Modifier.border(1.dp, Color.Black))
      }
    }
    Text("Ctr ${ctr.value}",
      Modifier
        .align(Alignment.BottomCenter)
        .offset(y = -20.dp))
  }
}
o
The
Popup
composable is broken atm. Use
DropDown
DropdownMenu
instead. Don't be confused by the name
DropDown
DropdownMenu
, it produces a
Popup
.
l
Could you file a bug please?