Skip to content

Commit

Permalink
Update onFocusChanged in SelectableLazyColumn (#372)
Browse files Browse the repository at this point in the history
The onFocusChanged function in SelectableLazyColumn has been updated to trigger onSelectFirstItem if the component receives focus and no items are currently active or selected. This ensures an item gets automatically selected in absence of any selected or active items, improving user experience and interaction flow.
  • Loading branch information
fscarponi authored Apr 30, 2024
1 parent b47ff64 commit b34d809
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,15 @@ public fun SelectableLazyColumn(
val focusManager = LocalFocusManager.current
val focusRequester = remember { FocusRequester() }
LazyColumn(
modifier = modifier.onFocusChanged { isFocused = it.hasFocus }
modifier = modifier
.onFocusChanged {
isFocused = it.hasFocus
with(state) {
if (isFocused && lastActiveItemIndex == null && selectedKeys.isEmpty()) {
keyActions.actions.onSelectFirstItem(keys, this)
}
}
}
.focusRequester(focusRequester)
.focusable(interactionSource = interactionSource)
.onPreviewKeyEvent { event ->
Expand Down

0 comments on commit b34d809

Please sign in to comment.