Menu
fun Menu(state: MenuState, modifier: Modifier = Modifier, content: @Composable MenuScope.() -> Unit)
fun Menu(modifier: Modifier = Modifier, state: MenuState = rememberMenuState(), ______deprecated: Unit, contents: @Composable MenuScope.() -> Unit)
Deprecated
This signature is going away in a future version
Replace with
Menu(state,modifier,contents)Content copied to clipboard
An unstyled component for Compose Multiplatform that can be used to implement Dropdown Menus with the styling of your choice. Fully accessible, supports keyboard navigation and open/close animations.
For interactive preview & code examples, visit Dropdown Menu Documentation.
Basic Example
val options = listOf("United States", "Greece", "Indonesia", "United Kingdom")
var selected by remember { mutableStateOf(0) }
val state = rememberMenuState(expanded = true)
Column(Modifier.fillMaxSize()) {
Menu(state, modifier = Modifier.align(Alignment.End)) {
MenuButton(
Modifier.clip(RoundedCornerShape(6.dp))
.border(1.dp, Color(0xFFBDBDBD), RoundedCornerShape(6.dp))
) {
Row(
modifier = Modifier.padding(horizontal = 14.dp, vertical = 10.dp),
verticalAlignment = Alignment.CenterVertically,
) {
Text("Options", style = defaultTextStyle.copy(fontWeight = FontWeight(500)))
Spacer(Modifier.width(4.dp))
Image(ChevronDown, null)
}
}
MenuContent(
modifier = Modifier.width(320.dp)
.border(1.dp, Color(0xFFE0E0E0), RoundedCornerShape(4.dp))
.background(Color.White)
.padding(4.dp),
exit = fadeOut()
) {
options.forEachIndexed { index, option ->
MenuItem(
modifier = Modifier.clip(RoundedCornerShape(4.dp)),
onClick = { selected = index }
) {
Text(option, modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp, horizontal = 4.dp))
}
}
}
}
Text("Selected = ${options[selected]}")
}Content copied to clipboard
Parameters
state
The state object to be used to control the menu's expanded state.
modifier
Modifier to be applied to the menu container.
content
The content of the menu, typically containing a MenuButton and MenuContent.