CamoMenu
Concept
1. Why
Menus show a short list of actions anchored to the element that opened them: an overflow "⋮" button, a right-click context menu, a split button's arrow. Unlike dialogs and sheets, a menu is an anchored popup, not a navigation entry. It opens next to its anchor, and closes on selection, outside tap or Esc, on both platforms, with no router involved.
2. Shape
Material mapping preview: M3 menus.
- Container:
surfaceContainer,shapes.extraSmall,level2. Width 112–280. - Items 48 tall, with
labelLargetext and a leading icon 24 inonSurfaceVariant. - Keyboard-shortcut text trails in
onSurfaceVariant.
3. API
Contract
fun CamoMenuAnchor(
items: List<CamoMenuEntry> = emptyList(),
panel: Widget? = null, // custom content in a CamoMenuPanel, instead of items (ADR-30)
controller: CamoMenuController? = null, // optional: open/close from outside
anchor: Widget (open: () -> Unit), // the element the menu attaches to
)
sealed interface CamoMenuEntry
data class CamoMenuItem(
val text: String,
val onClick: () -> Unit,
val leadingIcon: Widget? = null,
val trailingText: String? = null, // e.g. a keyboard shortcut "⌘C"
val tone: Tone = Default, // Error for destructive items ("Delete")
val enabled: Boolean = true,
val checked: Boolean? = null, // non-null → a checkable item (a checkmark when true)
) : CamoMenuEntry
data object CamoMenuDivider : CamoMenuEntry
data class CamoMenuGroup(val items: List<CamoMenuItem>, val exclusive: Boolean = false) : CamoMenuEntry
// exclusive = true → the checked items are announced as radio items ("Sort by: Newest")
fun CamoContextMenuArea(items: List<CamoMenuEntry>, content: Slot) // right-click / long-press menu
Selecting an item runs onClick and closes the menu, checkable items included (the app flips checked). Submenus are M16 (below).
Building block (ADR-30): CamoMenuPanel(content: Slot) is the menu's skin surface with menu semantics, arrow-key focus movement between its focusable children, and Esc to close. It's for menus with custom rows (a color picker, an account switcher), opened from a CamoMenuAnchor(panel = …) instead of items. Standard rows can mix in with CamoMenuItemRow(item).
State → renderer: MenuState(expanded, highlightedIndex). Slots: MenuSlots(entries). Core positions the popup and handles focus and keys. The renderer draws the container and rows.
Tokens used
colors.surfaceContainer,onSurface,onSurfaceVariant, the tone family for destructive itemsshapes.extraSmall,elevation.level2,typography.labelLargemotion.durationShort(scale + fade in from the anchor side)
Component theme
theme.components.menu: MenuTheme?. Every field is nullable in the theme. The skin's defaults(theme) fills whatever isn't set (Material defaults shown). See Theme §3.10.
| Field | Type | Material default | What it's for |
|---|---|---|---|
shape | Shape | shapes.extraSmall | container corners |
minWidth / maxWidth | Dp | 112 / 280 | width bounds |
itemHeight | Dp | 48 | row height |
contentPadding | Padding | vertical 8 | container padding |
textStyle | CamoTextStyle | labelLarge | item text |
iconSize | Dp | 24 | leading icons |
elevation | ElevationLevel | Level2 | depth |
checkPosition | Leading | Trailing | Trailing | where the checkmark of a checked item sits (ADR-28; Apple and Fluent: Leading) |
colors | MenuColors(container, text, icon, trailingText) | surfaceContainer, onSurface, onSurfaceVariant, onSurfaceVariant | every color it uses |
Accessibility
- The anchor announces "has popup" and expanded/collapsed.
- The menu has role menu, and items role menuitem ("Delete, menu item, 3 of 4"). A checkable item is a menu item checkbox ("Show hidden files, checked"); in an exclusive
CamoMenuGroupit's a menu item radio ("Newest, selected, 1 of 3"). - Keyboard: Enter/Space/Down on the anchor opens it and focuses the first item. Up/Down move, Home/End jump, Enter selects, Esc closes and returns focus to the anchor. Typing a letter jumps to the next item starting with it.
- The screen reader stays inside the open menu. An outside tap or a screen-reader "dismiss" closes it.
4. Build steps
- The anchored-popup primitive in core (positioning with edge flipping, outside tap, Esc, focus in and back).
CamoSelectandCamoTooltipreuse it. CamoMenuAnchor,CamoMenuController, entries,CamoContextMenuArea(right-click on desktop/web, long-press on touch).MenuRenderer, and the DebugSkin renderer.- Sample: an overflow menu in the top bar (Share, Edit, divider, Delete in
Errortone), and a context menu on a list row. - Tests:
- opens below the anchor and flips above near the bottom edge;
- selecting runs the action and closes;
- checked items draw the check at
checkPositionand announce checkbox or radio semantics; - Esc returns focus to the anchor;
- arrow keys and type-ahead;
- announcements.
Done when
- The overflow menu and the context menu work by touch, mouse, keyboard and screen reader on every platform.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Menu near a screen edge | Flips to the other side, or shifts inward. It never overflows the window. |
| Long lists of items | The menu scrolls after its max height (the space to the window edge). More than ~8 items suggests a sheet or CamoSelect instead. |
| Opening a dialog from a menu item | The menu closes first, then the action runs, so the dialog isn't stacked over a closing menu. |
| Checkable items (settled 2026-09-27) | checked: Boolean? on CamoMenuItem; CamoMenuGroup(exclusive = true) for single choice (sort order). Items with and without checks in the same menu keep their text aligned (a reserved check column when checkPosition = Leading). |
| Submenus | M16 (below). |
| Custom menu content | CamoMenuPanel (ADR-30). Custom rows must be focusable and have a label; the panel moves focus with the arrow keys and closes on Esc or an outside tap. |
The anchored popup (CamoAnchoredPopup on Kotlin, an internal route on Flutter) and the panel part of the renderer (MenuRenderer.Panel, CamoMenuPanel) ship in M5 for the date and time fields; MenuTheme already carries every field. M6 adds the item part, CamoMenuAnchor and the entries. The popup takes focus when it opens.
- The renderer gains an
Itempart:MenuItemState(text, trailingText, tone, enabled, checked, reserveCheck, reserveIcon, interaction)andMenuItemSlots(leadingIcon). Core works outreserveCheckandreserveIconacross the menu, so text stays aligned when only some items have a check or an icon. MenuThemegainscheckIcon: the checkmark of a checked item, and of the current option in a select's sheet.- The menu role sits on the menu's content, not on
CamoMenuPanel, because the date and time pickers use the panel too. - Opening from the keyboard focuses the first item; a pointer or touch opening doesn't, so no focus ring shows after a click.
- "Close then act": the action runs after the frame in which the menu closed, from a scope that outlives the popup (the anchor's).
- Menu text takes the row's free space and the shortcut follows it; a menu wider than
maxWidthellipsizes the text.
Context menus in desktop apps nest (Reset ▸ Soft / Mixed / Hard; Copy ▸ Hash / Message).
data class CamoMenuSubmenu(
val text: String,
val items: List<CamoMenuEntry>, // a submenu may hold submenus
val leadingIcon: Widget? = null,
val enabled: Boolean = true,
) : CamoMenuEntry
- Row: a submenu row looks like an item with a trailing chevron (mirrored in right-to-left) drawn by the skin:
MenuItemStategainshasSubmenuandsubmenuOpen, so the Item part of the renderer draws the chevron and an "open" state. No new renderer. - Opening: hover opens it after 250 ms; a click, Enter and Right (Left in RTL) open it at once and focus its first item. Moving to another row of the parent closes it after a short grace (120 ms), so the pointer can cross a neighbour on its way to the child.
- Closing: Left (Right in RTL) and Esc close only the submenu and return focus to its row; Esc on the root closes the whole chain. Selecting a leaf runs the action and closes every level (the existing "close then act" rule).
- Placement: the child opens beside its row (end side, its first item aligned with the row), flips to the start side when there is no room, and shifts up near the bottom edge. This needs the anchored-popup primitive to learn a side placement (today it is below or above only) and a non-modal child mode: the child must not turn a tap on its parent into an outside tap.
- Touch: a tap opens the submenu as a second panel next to (or over) the first; Back closes only the child.
- Semantics: the row is a menu item with "has popup" and expanded or collapsed; the child is a menu, announced "Soft, menu item, 1 of 3".
- Type-ahead and arrows work inside each level; Up and Down never cross levels.
Open for review: (1) depth: proposed any depth (a level is the same code as the first), with a note that more than two levels is a design smell; (2) the hover delay of 250 ms and the 120 ms grace (the common values; a theme field submenuDelay is a later option); (3) a safe-triangle for the pointer path is not in the first cut (the grace covers most cases).
Implementation
1. Why
Menus are the core anchored popup, reused by CamoSelect and CamoTooltip. Compose Multiplatform's Popup gives a separate layer on every target; core adds the positioning that flips at window edges, focus in and back out, arrow keys and type-ahead, checkable items, context menus (right-click and long-press), and the CamoMenuPanel building block (ADR-30).
2. Shape
3. API
@Composable
public fun CamoMenuAnchor(
modifier: Modifier = Modifier,
items: List<CamoMenuEntry> = emptyList(),
panel: (@Composable () -> Unit)? = null, // custom content inside a CamoMenuPanel (ADR-30)
controller: CamoMenuController? = null,
anchor: @Composable (open: () -> Unit) -> Unit,
)
public sealed interface CamoMenuEntry
public data class CamoMenuItem(val text: String, val onClick: () -> Unit, val leadingIcon: (@Composable () -> Unit)? = null,
val trailingText: String? = null, val tone: Tone = Tone.Default, val enabled: Boolean = true,
val checked: Boolean? = null) : CamoMenuEntry
public data object CamoMenuDivider : CamoMenuEntry
public data class CamoMenuGroup(val items: List<CamoMenuItem>, val exclusive: Boolean = false) : CamoMenuEntry
@Composable public fun CamoMenuPanel(modifier: Modifier = Modifier, onClose: () -> Unit, content: @Composable ColumnScope.() -> Unit)
@Composable public fun CamoMenuItemRow(item: CamoMenuItem, onSelected: () -> Unit, modifier: Modifier = Modifier)
@Composable public fun CamoContextMenuArea(items: List<CamoMenuEntry>, modifier: Modifier = Modifier, content: @Composable () -> Unit)
public class CamoMenuController { public fun open(); public fun close(); public val isOpen: Boolean }
- Positioning:
CamoFlipPositionProvider : PopupPositionProviderplaces the menu below the anchor's start edge; if it doesn't fit below it goes above; horizontally it shifts inward to stay in the window (RTL-aware). The height is capped to the available space, and the panel scrolls. - Focus:
Popup(properties = PopupProperties(focusable = true)); the first enabled row gets focus via aFocusRequesterwhen opened by keyboard (touch opening doesn't show a focus ring). On close, focus returns to the anchor (anchorFocusRequester.requestFocus()). - Keys (
onPreviewKeyEventon the panel): Up/Down move, Home/End jump, Enter/Space select, Esc closes, printable keys jump to the next row whose text starts with the typed prefix (500 ms buffer). - Semantics: Compose has no menu roles, so rows use
Role.Button(plain),Role.CheckboxwithtoggleableState(checkable), orRole.RadioButtonwithselectedinsideselectableGroup()(exclusive group); the panel setspaneTitleandcollectionInfo. - Context menus:
pointerInputdetects a secondary-button press (desktop, web) anddetectTapGestures(onLongPress = …)(touch), opening at the pointer offset. On Android and iOS a long press doesn't also trigger the content's click. - Close then act: selecting closes the popup first, then runs
onClickin the next frame, so an action that opens a dialog doesn't stack over a closing menu.
4. Build steps
CamoFlipPositionProvider, the popup plumbing,CamoMenuPanel(shared withCamoSelect).CamoMenuAnchor, entries,CamoMenuItemRow,CamoMenuController,CamoContextMenuArea;MenuTheme/Style(withcheckPosition); the DebugSkin renderer.commonTest/ UI tests: flips near the bottom edge; selecting runs and closes; Esc returns focus; arrows and type-ahead; checkable and exclusive semantics; a custom panel keeps arrow navigation.
Done when
- The overflow menu, a "Sort by" exclusive group, a context menu on a list row and a custom-panel account switcher work by touch, mouse, keyboard and screen reader on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
Web (wasmJs) right-click | Core prevents the browser's context menu only inside CamoContextMenuArea. |
| iOS popups | CMP renders the popup in the same UIKit view; focus and VoiceOver move into it via paneTitle. |
| Window resized while open | The position provider re-runs; if the anchor leaves the window, the menu closes. |
CamoMenuPanel(modifier, content)keeps its M5 signature: the anchored popup already turns Esc, back and an outside tap into the close.- A secondary-button press isn't a "down" for Compose's gesture helpers, so
CamoContextMenuAreareads right-clicks from the rawPointerEventType.Press; the touch long press is a separate gesture that consumes the rest of the press, so the content isn't clicked. - Compose for web already suppresses the browser's context menu over its whole canvas, so core adds nothing there.
- The selected item's action runs in the anchor's
rememberCoroutineScopea frame after the close. A scope inside the popup is cancelled when the popup leaves, which dropped the action on the web. - Rows use
Role.Button,Role.CheckboxwithtoggleableState, orRole.RadioButtonwithselectedinsideselectableGroup().
CamoMenuSubmenu is a new CamoMenuEntry. CamoAnchoredPopup gains placement: PopupPlacement (Below, Beside) and modal: Boolean; a child is a second Popup (a separate layer on every target) with focusable = true and dismissOnClickOutside = false, dismissed by the parent's state. CamoFlipPositionProvider gets the side placement: end of the row, flip to start, clamp to the window.
MenuItemStategainshasSubmenuandsubmenuOpen; the skin's Item part draws the trailing chevron (mirrored in RTL). No new renderer.- Tests: opens by hover (250 ms), click, Enter and Right; closes by Left and Esc without closing the root; a leaf closes every level; flips at the end edge and in RTL; shifts up near the bottom; a tap on the parent while a child is open closes the child, not the menu; semantics ("has popup", expanded, 1 of n).
- Done when: a two-level context menu works by mouse, keyboard and screen reader on Kotlin, with Material, Cupertino, Fluent, Carbon and Minimal.