Skip to content

Commit 9f378d3

Browse files
authored
Merge pull request #56 from y-maskin/y-maskin-custom-selected-object-mapping
Update SearchableExpandedDropDownMenuMaterial3.kt
2 parents c04b601 + e005366 commit 9f378d3

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

searchable-dropdown/src/main/java/com/kanyidev/searchable_dropdown/SearchableExpandedDropDownMenuMaterial3.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import androidx.compose.ui.unit.dp
7272
* @param showDefaultSelectedItem If set to true it will show the default selected item with the position of your preference, it's value is set to false by default
7373
* @param defaultItemIndex Pass the index of the item to be selected by default from the dropdown list. If you don't provide any the first item in the dropdown will be selected
7474
* @param defaultItem Returns the item selected by default from the dropdown list
75+
* @param selectedDisplayText Returns the selected item and allow mapping it to a custom display text. If no mapping provided, item.toString() will be used by default
7576
*/
7677
@OptIn(ExperimentalComposeUiApi::class, ExperimentalComposeUiApi::class)
7778
@Composable
@@ -107,6 +108,7 @@ fun <T> SearchableExpandedDropDownMenuMaterial3(
107108
showDefaultSelectedItem: Boolean = false,
108109
defaultItemIndex: Int = 0,
109110
defaultItem: (T) -> Unit = {},
111+
selectedDisplayText: ((T) -> String)? = null,
110112
reset: Boolean = false,
111113
parentTextFieldShape: CornerBasedShape = MaterialTheme.shapes.medium,
112114
textStyle: TextStyle = MaterialTheme.typography.bodySmall,
@@ -253,7 +255,8 @@ fun <T> SearchableExpandedDropDownMenuMaterial3(
253255
.fillMaxWidth(),
254256
onClick = {
255257
keyboardController?.hide()
256-
selectedOptionText = selectedItem.toString()
258+
selectedOptionText = selectedDisplayText?.invoke(selectedItem)
259+
?: selectedItem.toString()
257260
onDropDownItemSelected(selectedItem)
258261
searchedOption = ""
259262
expanded = false
@@ -269,4 +272,4 @@ fun <T> SearchableExpandedDropDownMenuMaterial3(
269272
}
270273
}
271274

272-
private val DropdownMenuVerticalPadding = 8.dp
275+
private val DropdownMenuVerticalPadding = 8.dp

0 commit comments

Comments
 (0)