ListBox

fun <T> ListBox(expanded: Boolean, items: List<T>, itemContent: @Composable (T) -> Unit, onDismissRequest: () -> Unit, modifier: Modifier = Modifier, contentPadding: PaddingValues = MenuDefaults.DropdownMenuItemContentPadding, useSafeHeight: Boolean = true, onItemClick: (T) -> Unit?)(source)

Wrapped Material DropdownMenu with Skapa features, used to display select options

Note: for group header use the constructor that use ListBoxItemsParams

Parameters

expanded

Whether the ListBox is currently open and visible to the user

items

list of items to be drawn as options.

itemContent

Composable function of how each item is going to be drawn.

onDismissRequest

Called when the user requests to dismiss the ListBox, such as by tapping outside the ListBox's bounds

modifier

Modifier to be applied to the ListBox.

contentPadding

the padding applied to the content of this ListBox

useSafeHeight

set this to false to opt-out from the vertical WindowInsets.

onItemClick

option callback that is triggered when on option es selected. Selected object comes as a parameter of the callback. Provide null in case the item should not be clickable or you want to handle the click with itemContent composable

Type Parameters

T

The type of items in the list.

See also

Samples

net.ikea.skapa.ui.samples.ListBoxSample
fun <T : ListBoxItemHeader> ListBox(expanded: Boolean, itemParams: ListBoxItemsParams<T>, onDismissRequest: () -> Unit, modifier: Modifier = Modifier, useSafeHeight: Boolean = true)(source)

Wrapped Material DropdownMenu with Skapa features, used to display select options

Parameters

expanded

Whether the ListBox is currently open and visible to the user

itemParams

ListBoxItemsParams is group of parameters represents a list of items that Implement ListBoxItemHeader interface and is used to separate the items by headers

onDismissRequest

Called when the user requests to dismiss the ListBox, such as by tapping outside the ListBox's bounds

modifier

Modifier to be applied to the ListBox.

useSafeHeight

set this to false to opt-out from the vertical WindowInsets.

Type Parameters

T

The type of items in the list that implement ListBoxItemHeader.

Samples

var expanded by remember { mutableStateOf(false) }
var itemsSelected by remember { mutableStateOf(false) }
var selectValue by remember { mutableStateOf(ListBoxSample.triggerHint) }
SkapaTheme2(isSystemInDarkTheme()) {
    Box {
        Pill(
            label = selectValue,
            selected = itemsSelected,
            leadingItem = null,
            trailingIconId = null,
            badgeValue = null
        ) {
            expanded = true
        }
        ListBox(
            expanded = expanded,
            itemParams = ListBoxItemsParams(
                items = ListBoxSample.headerList,
                itemContent = {
                    ListViewItem(
                        title = it.label,
                        trailingControl = ListViewItemControls.RadioButton(it.label == selectValue),
                        textStyle = ListViewItemTextStyle.Regular,
                        onClick = null,
                        size = ListViewItemSize.Small
                    )
                },
                onItemClick = {
                    selectValue = it.label
                    expanded = false
                    itemsSelected = true
                }
            ),
            onDismissRequest = {
                expanded = false
            },
            modifier = Modifier.width(ListBoxSample.maxListWidth)
        )
    }
}