Dropdown

fun <K : Any> Dropdown(expanded: Boolean, placeholder: String, options: Map<K, DropdownOption>, selectedOption: K?, onOptionSelected: (K) -> Unit, onExpandedChange: (Boolean) -> Unit, onDismissRequest: () -> Unit, modifier: Modifier = Modifier, label: String? = null, state: DropdownInteractiveState = DropdownInteractiveState.Enabled, dropdownSize: DropdownSize = DropdownSize.Large, isInlined: Boolean = false, minVisibleItems: Int = 4)

Dropdown

Dropdowns present a list of options from which a user can select one option. A selected option can represent a value in a form, or can be used as an action to filter or sort existing content.

Only one option can be selected at a time.

  • By default, the dropdown displays placeholder text in the field when closed.

  • Clicking on a closed field opens a menu of options.

  • Selecting an option from the menu closes it and the selected option text replaces the placeholder text in the field and also remains as an option in place if the menu is open.

(From Dropdown documentation)

Parameters

K

Type to identify the options.

expanded

Whether the dropdown is expanded or not.

placeholder

The text to be displayed in the field when no option is selected.

options

The options to be displayed in the dropdown menu. A map signature ensures that the

selectedOption

The currently selected option. When not null, the option associated with this key will be displayed in the field. keys are unique and can be used to identify the selected option. The strings associated with each key are the texts to be displayed in the dropdown menu.

onOptionSelected

Callback invoked when an option is selected. The selected option key is passed as a parameter, and the callback should be used to update a remembered state with the new value.

onExpandedChange

Callback invoked when the expanded state of the dropdown changes. It should be used to update a remembered state with the new value.

onDismissRequest

Callback invoked when the dropdown menu should be dismissed.

modifier

The modifier to be applied to the dropdown.

label

The label to be displayed above the dropdown field (optionnal). NOTE: This label is provided as a convenience because its implementation may be very specific across contexts. You may need to implement your own label if the provided one does not meet your requirements.

state

The DropdownInteractiveState of the dropdown.

dropdownSize

The size of the dropdown, in terms of height. Defaults to DropdownSize.Large.

isInlined

Whether the dropdown should have the inline modification or not.

minVisibleItems

The minimum number of items to be visible in the dropdown menu before the user needs to scroll. This value is used to calculate the height of the menu. Defaults to 4.

Throws

If the options map is empty.


fun <K : Any> Dropdown(placeholder: String, options: Map<K, DropdownOption>, selectedOption: K?, onOptionSelected: (K) -> Unit, modifier: Modifier = Modifier, label: String? = null, state: DropdownInteractiveState = DropdownInteractiveState.Enabled, dropdownSize: DropdownSize = DropdownSize.Large, isInlined: Boolean = false, minVisibleItems: Int = 4)

Dropdown

Dropdowns present a list of options from which a user can select one option. A selected option can represent a value in a form, or can be used as an action to filter or sort existing content.

Only one option can be selected at a time.

  • By default, the dropdown displays placeholder text in the field when closed.

  • Clicking on a closed field opens a menu of options.

  • Selecting an option from the menu closes it and the selected option text replaces the placeholder text in the field and also remains as an option in place if the menu is open.

This overload is a convenience function that uses a mutable state to manage the expanded state.

(From Dropdown documentation)

Parameters

K

Type to identify the options.

placeholder

The text to be displayed in the field when no option is selected.

options

The options to be displayed in the dropdown menu. A map signature ensures that the

selectedOption

The currently selected option. When not null, the option associated with this key will be displayed in the field. keys are unique and can be used to identify the selected option. The strings associated with each key are the texts to be displayed in the dropdown menu.

onOptionSelected

Callback invoked when an option is selected. The selected option key is passed as a parameter, and the callback should be used to update a remembered state with the new value.

modifier

The modifier to be applied to the dropdown.

label

The label to be displayed above the dropdown field (optionnal).

state

The DropdownInteractiveState of the dropdown.

dropdownSize

The size of the dropdown, in terms of height. Defaults to DropdownSize.Large.

isInlined

Whether the dropdown should have the inline modification or not.

minVisibleItems

The minimum number of items to be visible in the dropdown menu before the user needs to scroll. This value is used to calculate the height of the menu. Defaults to 4.

Throws

If the options map is empty.