Skip to content

ListPopup

ListPopup is a popup list component in Miuix used to display a popup menu with multiple options. It provides a lightweight, floating temporary list suitable for various dropdown menus, context menus, and similar scenarios.

WARNING

ListPopup must be used within a Scaffold component!

Import

kotlin
import top.yukonga.miuix.kmp.basic.ListPopup
import top.yukonga.miuix.kmp.basic.ListPopupColumn

Basic Usage

The ListPopup component can be used to create simple dropdown menus:

kotlin
var showPopup = remember { mutableStateOf(false) }
var selectedIndex by remember { mutableStateOf(0) }
val items = listOf("Option 1", "Option 2", "Option 3")

Scaffold {
    Box {
        TextButton(
            text = "Click to show menu",
            onClick = { showPopup.value = true }
        )
        ListPopup(
            show = showPopup,
            onDismissRequest = { showPopup.value = false } // Close the popup menu
        ) {
            ListPopupColumn {
                items.forEachIndexed { index, string ->
                    DropdownImpl(
                        text = string,
                        optionSize = items.size,
                        isSelected = selectedIndex == index,
                        onSelectedIndexChange = {
                            selectedIndex = index
                            showPopup.value = false // Close the popup menu
                        },
                        index = index
                    )
                }
            }
        }
    }
}

Component States

Different Alignments

ListPopup can be set with different alignment options:

kotlin
var showPopup = remember { mutableStateOf(false) }

ListPopup(
    show = showPopup,
    onDismissRequest = { showPopup.value = false } // Close the popup menu
    alignment = PopupPositionProvider.Align.Left
) {
    ListPopupColumn {
        // Custom content
    }
}

Disable Window Dimming

kotlin
var showPopup = remember { mutableStateOf(false) }

ListPopup(
    show = showPopup,
    onDismissRequest = { showPopup.value = false } // Close the popup menu
    enableWindowDim = false // Disable dimming layer
) {
    ListPopupColumn {
        // Custom content
    }
}

Properties

ListPopup Properties

Property NameTypeDescriptionDefault ValueRequired
showMutableState<Boolean>State object controlling popup visibility-Yes
popupModifierModifierModifier applied to the popup listModifierNo
popupPositionProviderPopupPositionProviderPosition provider for the popupListPopupDefaults.DropdownPositionProviderNo
alignmentPopupPositionProvider.AlignAlignment of the popup listPopupPositionProvider.Align.RightNo
enableWindowDimBooleanWhether to enable dimming layertrueNo
shadowElevationDpShadow elevation of the popup11.dpNo
onDismissRequest(() -> Unit)?Callback when popup is dismissednullNo
maxHeightDp?Maximum height of the popup listnull (auto-calculated)No
minWidthDpMinimum width of the popup list200.dpNo
content@Composable () -> UnitContent of the popup list-Yes

ListPopupDefaults Object

The ListPopupDefaults object provides default settings for the ListPopup component.

Properties

Property NameTypeDescription
DropdownPositionProviderPopupPositionProviderPosition provider for dropdown scenarios
ContextMenuPositionProviderPopupPositionProviderPosition provider for context menus

PopupPositionProvider Interface

The PopupPositionProvider interface defines methods for calculating popup list positions.

PopupPositionProvider.Align Options

Option NameDescription
LeftAlign to the left of the window
RightAlign to the right of the window
TopLeftAlign to the top-left of the window
TopRightAlign to the top-right of the window
BottomLeftAlign to the bottom-left of the window
BottomRightAlign to the bottom-right of the window

Advanced Usage

Custom Content Layout

kotlin
var showPopup = remember { mutableStateOf(false) }

Scaffold {
    Box {
        TextButton(
            text = "Click to show menu",
            onClick = { showPopup.value = true }
        )
        ListPopup(
            show = showPopup,
            minWidth = 250.dp,
            maxHeight = 300.dp,
            onDismissRequest = { showPopup.value = false } // Close the popup menu
            alignment = PopupPositionProvider.Align.BottomRight,
        ) {
            ListPopupColumn {
                Column(modifier = Modifier.padding(16.dp)) {
                    Text(
                        "Custom Title",
                    )
                    Spacer(modifier = Modifier.height(8.dp))
                    HorizontalDivider()
                    Spacer(modifier = Modifier.height(8.dp))
                    Text("This is a custom content popup menu. You can add various components as needed.")
                    Spacer(modifier = Modifier.height(16.dp))
                    Row(
                        modifier = Modifier.fillMaxWidth(),
                        horizontalArrangement = Arrangement.End
                    ) {
                        TextButton(
                            text = "Confirm",
                            onClick = { showPopup.value = false } // Close the popup menu
                        )
                    }
                }
            }
        }
    }
}

Released under the Apache-2.0 License