Hi. I like to have a modal dialog the user must fi...
# compose-desktop
m
Hi. I like to have a modal dialog the user must first close before any actions can be done. However, in my app the menuBar is still active. Does anybody know how to make the AlertDialog really modal? (sample code in next posting)
Copy code
@OptIn(ExperimentalMaterialApi::class)
fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        var text by mutableStateOf("Nothing clicked")

        MenuBar {
            Menu("Test") {
                Item("Menu item") { text = "Menu item clicked" }
            }
        }

        Button(onClick = { text = "Button clicked " }) {
            Text(text)
        }

        var showDialog by remember { mutableStateOf(true) }
        if (showDialog) {
            AlertDialog(
                onDismissRequest = { },
                text = { Text("Alert dialog") },
                confirmButton = {
                    TextButton(onClick = { showDialog = false }) {
                        Text("ok")
                    }
                }
            )
        }
    }
}
a
Note that on MacOS X, the menubar is not in the window, so even a window-level modal dialog won’t prevent the menubar from being used.
m
Thanks for the quick reply! I don't use a Mac. Hence, this is interesting. I have to check if my Swing application has the same problem :) So, I will simply try to disable the menubar or catch any event fired from it while a "modal" dialog is displayed.
a
Sounds like a reasonable workaround