Skip to content

DropDownMenu: rest of the window is clickable when expanded #2586

@wiiznokes

Description

@wiiznokes

I'm trying to create a simple DropDownMenu with an IconButton to expand it, but when expanded is true, and we click on the icon button, onDismissRequest is called in the first place but onClick of the icon button is also called. I tried the same thing on Android and the onClick function is not called.

I don't know if it has to be different on Desktop but I can't figure it out a solution to this problem.
Here is a simplified version of my code:

@Composable
fun dropDownMenu() {
    val expanded = remember { mutableStateOf(false) }
    Row {
        Text("label")
        IconButton(
            onClick = { expanded.value = !expanded.value }
        ) {
            Icon(
                painter = when (expanded.value) {
                    true -> getIcon("expand_less")
                    false -> getIcon("expand_more")
                }
            )
        }
    }
    DropdownMenu(
        expanded = expanded.value,
        onDismissRequest = { expanded.value = false }
    ) {
        DropdownMenuItem(onClick = {}) {
            Text("content")
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdesktop

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions