CamoPopover
Concept
1. Why
A popover is a non-modal panel anchored to a control, for content that is richer than a menu and lighter than a dialog: a few lines of text, a small form, an inline picker, one or two actions (Apple's popover, Fluent's Popover and TeachingPopover, Material's rich tooltip). Unlike a dialog it doesn't dim the screen, and unlike a menu its content is arbitrary. It opens next to its anchor, closes on an outside tap or Esc, and hands focus back to the anchor.
2. Shape
Split of duties
| Core (popover) | Skin (renderer) |
|---|---|
anchoring and edge flipping (the anchored-popup primitive, ADR-30), the open state, outside tap and Esc, focus in and back, semantics | container color, shape and depth, the arrow, title and action placement, padding |
Material mapping preview: the M3 rich tooltip (there is no popover in Material).
- Container
surfaceContainer,shapes.medium,level2, max width 320. - Title
titleSmall, bodybodyMediuminonSurfaceVariant, actions as ghost buttons at the end. - No arrow.
3. API
Contract
fun CamoPopover(
open: Boolean,
onDismissRequest: () -> Unit,
anchor: Slot, // the element the popover points at; it stays in the layout
title: String? = null,
actions: Slot? = null, // buttons at the bottom end (CamoButton Ghost / Solid)
placement: PopoverPlacement = Auto, // Auto | Bottom | Top | Start | End
content: Slot, // arbitrary layout content
)
// building block (ADR-30): the skin's popover surface and semantics for content you position yourself
fun CamoPopoverPanel(title: String? = null, actions: Slot? = null, content: Slot)
Visibility is state (open), not a route: the app's button toggles it, like every controlled component (ADR-30). Auto opens below the anchor, flips above when there is no room, and tries the sides when asked (Start/End). The renderer is told where the anchor is so it can draw an arrow.
State → renderer: PopoverState(placement, arrowOffset) (placement is the one actually used after flipping; arrowOffset is where the anchor's center is along the edge, for the arrow). Slots: PopoverSlots(title?, content, actions?).
Tokens used
colors.surfaceContainer,onSurface,onSurfaceVariant,outlineVariant(the hairline skins draw)shapes.medium,elevation.level2,typography.titleSmall/bodyMediumspacing.lpadding,spacing.sbetween title, content and actionsmotion.durationShort(scale and fade in from the anchor side)
Component theme
theme.components.popover: PopoverTheme?. 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.medium | container corners |
maxWidth | Dp | 320 | the widest the panel gets |
padding | Padding | 16 | around the content |
showArrow | Boolean | false | an arrow pointing at the anchor (Apple and Fluent: true) |
arrowSize | Size | 16 × 8 | the arrow |
elevation | ElevationLevel | Level2 | depth |
titleStyle | CamoTextStyle | titleSmall | the title |
gap | Dp | 8 | space between anchor and panel |
colors | PopoverColors(container, title, content, border?) | surfaceContainer, onSurface, onSurfaceVariant, none | every color it uses |
Accessibility
- The anchor announces "has popup" and expanded or collapsed.
- The panel is a non-modal group named by its title; it is announced when it opens.
- Keyboard: opening moves focus into the panel (the first focusable child, or the panel itself); Tab stays inside while it is open; Esc closes it and returns focus to the anchor. An outside tap or the screen-reader dismiss action closes it.
- It never traps a pointer: taps outside close it and still reach what is under them only when the app wants that (default: they just close it).
4. Build steps
PopoverPlacementand the placement rules on the anchored-popup primitive (side placement, the arrow offset).CamoPopover,CamoPopoverPanel,PopoverRenderer, the DebugSkin renderer.- Sample: a popover from a toolbar button with a title, a small form and two actions.
- Tests: open and close by tap, outside tap and Esc; focus in and back; placement flips at the window edge; the arrow follows the anchor; semantics.
Done when
- A popover opens from a button, closes on an outside tap or Esc, returns focus to its anchor, and reads as a group.
5. Edge cases
| Case | Decided behavior |
|---|---|
| Not enough room on any side | It is clamped inside the window and may overlap the anchor; the arrow still points at the anchor's center. |
| The anchor scrolls away | The popover follows the anchor while it is visible and closes through onDismissRequest when the anchor leaves the viewport. |
| A popover inside a popover or a dialog | Allowed; each closes on its own Esc, innermost first. |
| Touch devices | Same behavior; the outside tap closes it. On phones, a bottom sheet is usually the better presentation, and the app chooses. |
| Rich tooltip (hover) | Later (CamoRichTooltip on the same panel). |
- Controlled only?
openis state, with no uncontrolled trigger helper in v0.1 (a button'sonClicktoggles it). ACamoPopoverAnchor { toggle -> … }convenience like the menu's is cheap to add if you want it.- Arrow default: off in the core default, on for Apple and Fluent, per their guidelines.
PopoverState(placement, arrowOffset):placementis the side it really opened on after flipping, andarrowOffsetis where the anchor's center is along the panel's edge (from its top for the side placements, from its left for above and below). The arrow is drawn by the renderer in a margin ofarrowSize.heighton the facing edge, so the gap between the anchor and the panel includes it.- Placement is one pure function (below, then above; the side asked for, then the opposite, then below; centered on the anchor and kept inside the window) so it is tested without a window.
- The anchor must be one control: its semantics are merged to announce "has popup", expanded or collapsed.
- Opening and closing are state changes the app makes; an outside tap, back and Esc only call
onDismissRequest. Focus moves into the panel when it opens and back to the anchor when it closes. - The panel follows its anchor when the page scrolls (Flutter) and is placed again on a resize. Minimal draws a hairline panel with no arrow; Fluent a panel with shadow16 and an arrow.
Implementation
1. Why
Compose's Popup is the primitive; core's anchored popup already flips below or above and handles outside taps and Esc for menus. The popover adds side placement, the arrow offset, and the controlled open.
2. Shape
3. API
@Composable
public fun CamoPopover(
open: Boolean,
onDismissRequest: () -> Unit,
anchor: @Composable () -> Unit,
modifier: Modifier = Modifier,
title: String? = null,
actions: (@Composable RowScope.() -> Unit)? = null,
placement: PopoverPlacement = PopoverPlacement.Auto,
content: @Composable ColumnScope.() -> Unit,
)
- The anchor sits in a
Box; the popup is positioned from its bounds by aPopupPositionProviderthat returns the chosenPopoverPlacementback through state, so the renderer draws the arrow on the right edge. PopupProperties(focusable = true, dismissOnClickOutside = true, dismissOnBackPress = true); Esc throughonPreviewKeyEvent. Focus moves in with aFocusRequester, and whenopenbecomes false core requests focus on the anchor (the anchor modifier carries aFocusRequester).- Semantics: the anchor gets
stateDescriptionand a popup action; the panelpaneTitle = titleandisTraversalGroup.
4. Build steps
PopoverPlacement, the position provider,PopoverTheme/Style, state, slots, renderer, theCamoSkinfield.CamoPopover,CamoPopoverPanel, the DebugSkin renderer.- Tests: open and close by outside tap, back and Esc; focus returns to the anchor; the flip at the bottom edge; the side placements and RTL (Start and End mirror); the arrow offset.
Done when
- The Compose sample's popover works by touch, mouse, keyboard and screen reader on all targets.
5. Edge cases
| Case | Decided behavior |
|---|---|
open flips while the anchor recomposes | The popup is keyed on open; no flicker. |
| RTL | Start and End mirror. |
| Reduced motion | The scale-in becomes instant (the provider's reduced motion). |
- None specific.