compose-multiplatform icon indicating copy to clipboard operation
compose-multiplatform copied to clipboard

Context menu divider

Open JetpackDuba opened this issue 4 years ago • 1 comments

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.

JetpackDuba avatar Nov 04 '21 03:11 JetpackDuba

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

Burtan avatar Aug 07 '22 09:08 Burtan

Any update on this? Seems like the only way to do this now would be to create a completely custom context menu.

Sage-Kreiter avatar May 03 '23 16:05 Sage-Kreiter

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.

JetpackDuba avatar May 04 '23 14:05 JetpackDuba

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

dzirbel avatar Aug 15 '23 05:08 dzirbel