Skip to content

Select ​

A labeled dropdown over a list of options. The label sits above; help or error text sits below. The read-only anchor shows the selected option and a rotating chevron. Use it to pick one value from a small, known set.

Import ​

kotlin
import io.github.heartcoolman.prism.ui.PrismSelect

Basic usage ​

kotlin
var fruit by remember { mutableStateOf("Apple") }
PrismSelect(
    value = fruit,
    onValueChange = { fruit = it },
    options = listOf("Apple", "Banana", "Cherry"),
    label = "Fruit",
)

Typed options ​

PrismSelect is generic over T. Provide optionLabel to map each option to its display string; it defaults to toString().

kotlin
data class Country(val code: String, val name: String)

var country by remember { mutableStateOf(Country("US", "United States")) }
PrismSelect(
    value = country,
    onValueChange = { country = it },
    options = listOf(
        Country("US", "United States"),
        Country("JP", "Japan"),
    ),
    label = "Country",
    optionLabel = { it.name },
)

Error state ​

A non-empty error switches the border and message to danger and replaces helpText.

kotlin
PrismSelect(
    value = fruit,
    onValueChange = { fruit = it },
    options = listOf("Apple", "Banana"),
    label = "Fruit",
    error = "Please choose a fruit.",
)

API ​

ParameterTypeDefaultDescription
valueT—Currently selected option.
onValueChange(T) -> Unit—Called with the chosen option.
optionsList<T>—Options shown in the dropdown menu.
modifierModifierModifierLayout modifier applied to the column.
labelString?nullLabel rendered above the control.
placeholderString?nullPlaceholder shown in the anchor when applicable.
helpTextString?nullSupporting text shown below when not in error.
errorString?nullError message; non-empty switches the field to its error state and replaces helpText.
enabledBooleantrueWhether the dropdown can be opened.
fullWidthBooleanfalseStretch the control to fill the container width.
optionLabel(T) -> String{ it.toString() }Maps an option to its display string.

Released under the MIT License.