androidx.compose.ui.window

Popup

Composable function · from org.jetbrains.compose.ui:ui:1.12.2

A Popup shows content on top of the rest of the screen, placed next to where it is in your layout. Material's menus and tooltips use it.

Box {
    IconButton(onClick = { open = true }) { Icon(Icons.Filled.Info, "Info") }
    if (open) {
        Popup(alignment = Alignment.TopEnd, onDismissRequest = { open = false }) {
            Surface(shadowElevation = 4.dp) { Text("Saved 2 minutes ago", Modifier.padding(8.dp)) }
        }
    }
}

A popup is shown while it is in the composition. Keep a Boolean state and wrap it in if.

Prefer the Material versions when they fit: DropdownMenu for a list of actions, PlainTooltip for a short hint, AlertDialog for a question.

Aligned

Placed by alignment and offset, relative to its parent.

@Composable
fun Popup(
    alignment: Alignment = Alignment.TopStart,
    offset: IntOffset = IntOffset(0, 0),
    onDismissRequest: (() -> Unit)? = null,
    properties: PopupProperties = PopupProperties(),
    content: @Composable () -> Unit,
)

alignment: AlignmentOptional

Default: Alignment.TopStart

Where the popup goes, relative to its parent: Alignment.TopEnd puts it at the top end corner.

offset: IntOffsetOptional

Default: IntOffset(0, 0)

Moves the popup from its aligned position, in pixels.

onDismissRequest: (() -> Unit)?Optional

Default: null

Called when the user taps outside or presses back or Escape. Set your state to false here.

properties: PopupPropertiesOptional

Default: PopupProperties()

Whether the popup takes focus, closes on outside taps, and more. See PopupProperties or DialogProperties.

content: @Composable () -> UnitRequired

What the popup or dialog shows. Give it a background, like a Surface; it has none.

With a position provider

You compute the position yourself.

@Composable
fun Popup(
    popupPositionProvider: PopupPositionProvider,
    onDismissRequest: (() -> Unit)? = null,
    properties: PopupProperties = PopupProperties(),
    content: @Composable () -> Unit,
)

popupPositionProvider: PopupPositionProviderRequired

Computes the position yourself, from the parent's bounds and the popup's size.

Same as above: onDismissRequest, properties, content.

Windows