https://kotlinlang.org logo
Title
d

Dave Barrett

12/07/2021, 11:57 PM
Hi Guys! I'm a newbie to Compose(-Desktop) and I'm trying to build an app that has a pop-up window that takes some user input. For some reason, TextFields that I put in the Popup aren't allowing input. To test, I've put some TextFields in the main screen, and they seem to remain as the target for the keyboard input. This even though when you click on the TextFields on the Popup they respond as you'd expect, get focus, and just don't take keyboard input. The Popups are created as part of the screen over-all, and are composed or not via a state change.
@Composable
fun presentDialog() {
   val focusManager = LocalFocusManager.current
   if (showDialog.value) Popup(alignment = Alignment.TopStart, offset = IntOffset(150, 30)) {
      Column(modifier = Modifier.background(Color.White).border(width = 4.dp, color = Colours.person).padding(8.dp)) {
         val name = remember { mutableStateOf("Fred") }
         TextField(
               value = name.value,
               onValueChange = { name.value = it },
               label = { Text("Name") },
               maxLines = 1,
         )
         Spacer(Modifier.height(3.dp))
         val birthYear = remember { mutableStateOf("") }
         TextField(value = TextFieldValue(birthYear.value), onValueChange = { birthYear.value = it.text }, label = { Text("Birth Year: ") }, enabled = true)
         Row(Modifier.align(Alignment.CenterHorizontally)) {
            Button({
               println("clicked Cancel")
               showDialog.value = false
            }) { Text("Cancel") }
            Spacer(Modifier.width(6.dp))
            Button({
               println("clicked Add")
               showDialog.value = false
            }) { Text("Add Child") }
         }
      }
   }
}
Does anyone know what I'm doing wrong? thx, dave
i

Igor Demin

12/08/2021, 8:40 AM
Pass
focusable = true
to Popup, but don't forget to also set
onDismissRequest
(focusable Popup don't work well without it)
d

Dave Barrett

12/09/2021, 2:23 PM
Thank you! That has worked perfectly.
1