Skip to content

Commit

Permalink
Iterate on onSelectedItem in ListComboBox (#702)
Browse files Browse the repository at this point in the history
iterate on onSelectedItem in ListComboBox

Fixes #701

Signed-off-by: Ivan Morgillo <[email protected]>
  • Loading branch information
hamen authored Nov 25, 2024
1 parent af43be4 commit 8c1676e
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,10 @@ public fun ListComboBox(
}
}

fun onSelectedIndexesChange() = { selectedItems: List<Int> ->
if (selectedItems.isNotEmpty()) {
val selectedItemIndex = selectedItems.first()
selectedItem = selectedItemIndex
inputTextFieldState.setTextAndPlaceCursorAtEnd(items[selectedItemIndex])
onSelectedItemChange(items[selectedItemIndex])
}
fun onSelectedIndexChange(selectedItemIndex: Int) {
selectedItem = selectedItemIndex
inputTextFieldState.setTextAndPlaceCursorAtEnd(items[selectedItemIndex])
onSelectedItemChange(items[selectedItemIndex])
}

fun contentItems(
Expand Down Expand Up @@ -147,7 +144,11 @@ public fun ListComboBox(
modifier = Modifier.fillMaxWidth().heightIn(max = popupMaxHeight).padding(contentPadding),
selectionMode = SelectionMode.Single,
state = scrollState,
onSelectedIndexesChange = onSelectedIndexesChange(),
onSelectedIndexesChange = { selectedItemsIndexes ->
if (selectedItemsIndexes.isEmpty()) return@SelectableLazyColumn
if (selectedItemsIndexes.first() == selectedItem) return@SelectableLazyColumn
onSelectedIndexChange(selectedItemsIndexes.first())
},
content = contentItems(items, onHoverItemChange, listItemContent),
)
}
Expand Down

0 comments on commit 8c1676e

Please sign in to comment.