Skip to content

Commit

Permalink
add access to dismiss callback in dropdown inputs (#335)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Pajuelo Cabezas <[email protected]>
  • Loading branch information
Balcan authored Nov 28, 2024
1 parent 007f4b0 commit 44dafb4
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ private const val MAX_DROPDOWN_ITEMS_TO_SHOW = 50
* @param showSearchBar: config whether to show search bar in the bottom sheet.
* @param expanded: config whether the dropdown should be initially displayed.
* @param useDropDown: use dropdown if true. Bottomsheet with search capability otherwise.
* @param onDismiss: gives access to the onDismiss event.
* @param noResultsFoundString: text to be shown in pop up when no results are found.
*/
@OptIn(ExperimentalMaterial3Api::class)
Expand All @@ -98,6 +99,7 @@ fun InputDropDown(
expanded: Boolean = false,
useDropDown: Boolean = true,
loadOptions: () -> Unit,
onDismiss: () -> Unit = {},
noResultsFoundString: String = provideStringResource("no_results_found"),
searchToFindMoreString: String = provideStringResource("search_to_see_more"),
) {
Expand Down Expand Up @@ -160,6 +162,7 @@ fun InputDropDown(
currentItem = this
onItemSelected(index, this)
showDropdown = false
onDismiss()
},
)
}
Expand Down Expand Up @@ -187,6 +190,7 @@ fun InputDropDown(
},
onDismiss = {
showDropdown = false
onDismiss()
},
searchQuery = if (showSearchBar) {
searchQuery
Expand Down Expand Up @@ -221,7 +225,10 @@ fun InputDropDown(
) {
ExposedDropdownMenu(
expanded = showDropdown,
onDismissRequest = { showDropdown = false },
onDismissRequest = {
showDropdown = false
onDismiss()
},
modifier = Modifier.background(
color = SurfaceColor.SurfaceBright,
shape = RoundedCornerShape(Spacing8),
Expand All @@ -243,6 +250,7 @@ fun InputDropDown(
currentItem = this
onItemSelected(index, this)
showDropdown = false
onDismiss()
},
)
}
Expand Down

0 comments on commit 44dafb4

Please sign in to comment.