Skip to content

SuperDropdown

SuperDropdown is a dropdown menu component in Miuix that provides a title, summary, and a list of dropdown options. It supports click interaction and is commonly used in option settings and list selections.

WARNING

SuperDropdown must be used within a Scaffold component!

Import

kotlin
import top.yukonga.miuix.kmp.extra.SuperDropdown
import top.yukonga.miuix.kmp.extra.DropDownMode

Basic Usage

The SuperDropdown component provides basic dropdown menu functionality:

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

Scaffold {
    SuperDropdown(
        title = "Dropdown Menu",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}
kotlin
var selectedIndex by remember { mutableStateOf(0) }
val options = listOf("中文", "English", "日本語")

Scaffold {
    SuperDropdown(
        title = "Language Settings",
        summary = "Choose your preferred language",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it }
    )
}

Component States

Disabled State

kotlin
SuperDropdown(
    title = "Disabled Dropdown",
    summary = "This dropdown menu is currently unavailable",
    items = listOf("Option 1"),
    selectedIndex = 0,
    onSelectedIndexChange = {},
    enabled = false
)

SuperDropdown supports different dropdown position modes:

Normal Mode (Auto-adaptive based on click position)

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

Scaffold {
    SuperDropdown(
        title = "Normal Mode",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it },
        mode = DropDownMode.Normal // Default value
    )
}

Always on Right Mode

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

Scaffold {
    SuperDropdown(
        title = "Always on Right Mode",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it },
        mode = DropDownMode.AlwaysOnRight
    )
}

Properties

SuperDropdown Properties

Property NameTypeDescriptionDefault ValueRequired
itemsList<String>List of dropdown options-Yes
selectedIndexIntIndex of currently selected item-Yes
titleStringTitle of the dropdown menu-Yes
titleColorBasicComponentColorsTitle text color configurationBasicComponentDefaults.titleColor()No
summaryString?Summary description of dropdownnullNo
summaryColorBasicComponentColorsSummary text color configurationBasicComponentDefaults.summaryColor()No
dropdownColorsDropdownColorsColor configuration for dropdownDropdownDefaults.dropdownColors()No
modeDropDownModeDisplay mode of dropdown menuDropDownMode.NormalNo
modifierModifierModifier applied to the componentModifierNo
insideMarginPaddingValuesInternal content paddingBasicComponentDefaults.InsideMarginNo
maxHeightDp?Maximum height of dropdown menunullNo
enabledBooleanWhether component is interactivetrueNo
showValueBooleanWhether to show selected valuetrueNo
onClick(() -> Unit)?Additional callback on clicknullNo
onSelectedIndexChange((Int) -> Unit)?Callback when selection changes-Yes
Property NameTypeDescription
contentColorColorOption text color
containerColorColorOption background color
selectedContentColorColorSelected item text color
selectedContainerColorColorSelected item background color

Advanced Usage

Custom Colors

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val options = listOf("Red", "Green", "Blue")

Scaffold {
    SuperDropdown(
        title = "Custom Colors",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it },
        dropdownColors = DropdownDefaults.dropdownColors(
            selectedContentColor = Color.Red,
            selectedContainerColor = Color.Red.copy(alpha = 0.2f)
        )
    )
}

Limited Dropdown Height

kotlin
var selectedIndex by remember { mutableStateOf(0) }
val options = List(20) { "Option ${it + 1}" }

Scaffold {
    SuperDropdown(
        title = "Limited Height",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it },
        maxHeight = 200.dp // Limit dropdown menu maximum height to 200dp
    )
}

Hide Selected Value Display

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

Scaffold {
    SuperDropdown(
        title = "Hide Selected Value",
        items = options,
        selectedIndex = selectedIndex,
        onSelectedIndexChange = { selectedIndex = it },
        showValue = false // Hide selected value display
    )
}

Use with Dialog

kotlin
var showDialog = remember { mutableStateOf(false) }
var selectedIndex by remember { mutableStateOf(0) }
val themes = listOf("Light Mode", "Dark Mode", "System Default")

Scaffold {
    SuperArrow(
        title = "Theme Settings",
        onClick = { showDialog.value = true },
        holdDownState = showDialog.value
    )
    
    SuperDialog(
        title = "Theme Settings",
        show = showDialog,
        onDismissRequest = { showDialog.value = false }
    ) {
        Card {
            SuperDropdown(
                title = "Theme Selection",
                summary = "Choose your preferred theme appearance",
                items = themes,
                selectedIndex = selectedIndex,
                onSelectedIndexChange = { selectedIndex = it }
            )
        }
        
        Row(
            horizontalArrangement = Arrangement.SpaceBetween,
            modifier = Modifier.padding(top = 12.dp)
        ) {
            TextButton(
                text = "Cancel",
                onClick = { showDialog.value = false },
                modifier = Modifier.weight(1f)
            )
            Spacer(Modifier.width(16.dp))
            TextButton(
                text = "Confirm",
                onClick = { showDialog.value = false },
                modifier = Modifier.weight(1f),
                colors = ButtonDefaults.textButtonColorsPrimary()
            )
        }
    }
}

Released under the Apache-2.0 License