compose-multiplatform
compose-multiplatform copied to clipboard
Context menu divider
I haven't found a way of adding dividers to the options in a context menu like in the material design menu specification [Dropdown (Desktop)]
Are there any plans on adding them?
Looking at the current implementation, I'd suggest to change the ContextMenuArea to accept a list of ContextMenuElement, being this a parent interface (or super class, depening on the needs) of the current ContextMenuItem and a new class/object ContextMenuDivider. So you can pass to the ContextMenuArea a list of ContextMenuElement with whatever items and dividers you want.
There is also a need of nested ContextMenus which could be implemented similiary or at least give the user the chance to do it on his own with some kind of ContextMenuElement interface
Any update on this? Seems like the only way to do this now would be to create a completely custom context menu.
Personally I went for that route, as it's quite easy and allows customizing the ContextMenu as much as you want.
Here is an example of it https://github.com/JetpackDuba/Gitnuro/blob/main/src/main/kotlin/com/jetpackduba/gitnuro/ui/context_menu/ContextMenu.kt#L323
Then you just wrap your app with this new context menu:
CompositionLocalProvider(
values = arrayOf(LocalTextContextMenu provides AppPopupMenu())
) {
// Your app...
}
In this case AppPopupMenu could be an object rather than a class but it depends on your use case.
Small plug and another example for anyone still looking for an easy way to add dividers to context menus - I've created a simple library with support for material styling of context menus, including dividers: https://github.com/dzirbel/compose-material-context-menu