From b34d8092133afcb8937219e7d40c6990ab2671aa Mon Sep 17 00:00:00 2001 From: Fabrizio Scarponi <36624359+fscarponi@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:06:38 +0200 Subject: [PATCH] Update onFocusChanged in SelectableLazyColumn (#372) 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. --- .../jewel/foundation/lazy/SelectableLazyColumn.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt index 6f00f1e74..b6528b6b2 100644 --- a/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt +++ b/foundation/src/main/kotlin/org/jetbrains/jewel/foundation/lazy/SelectableLazyColumn.kt @@ -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 ->