Focus the first item at the start
When we:
- start a window, a dialog or popup, focus the first.
- call
focusManager.clearFocuswe should focus the first focusable node, otherwise remove the focus completely (the root node focusState = Inactive). In Compose 1.6.10 we always focus the root node on non-Android platforms.
A relevant change in Jetpack Compose was in https://android-review.googlesource.com/c/platform/frameworks/support/+/2813125
Welcome change, but it is a breaking one...
Welcome change, but it is a breaking one...
This happened in Jetpack Compose 1.7 with TextField as well (checked a screen with one TextField on 1.6 and 1.7)
After https://github.com/JetBrains/compose-multiplatform-core/pull/1352, it already works for ComposePanel
Right, but there one could think of it as making ComposePanel behave as a proper Swing widget, where initial selection is the norm.
This happened in Jetpack Compose 1.7 with TextField as well
Seems like it happens only when we use physical keyboard. Probably it wasn't intentional
+1 on this, just ran into this and was about to report as a bug.
Discovered when onPreviewKeyEvent wasn't initially working within my window.
I just ran into this again, and it's become somewhat high priority (for me) to find a fix or workaround.
It appears, in my testing, that it's impossible to receive keyboard events reliably in Compose Desktop, because if FocusManager.clearFocus is ever called, no further key events will ever be received by any composable.
I might be missing something, but if true, this is a huge issue. I just want Esc to close my window, but can't implement it reliably if clearFocus is called anywhere in my codebase.
Your issue is solvable using https://github.com/JetBrains/compose-multiplatform/issues/4764#issue-2280501620 (answered in Slack)
This enhancement won't solve it, as if there is no focusable elements, there will be no focus.
Agreed.
The challenge with hooking in to this at the Window level is implementing hotkeys adds tight coupling between window code and the screen-level code, which I try and keep separate.
It's also arguably an unexpected behaviour, which means it'll be a source of bugs. I know it was for me.
This is mentioned in the second bullet point in #4764, but just echoing here to give it a +1
Please check the following ticket on YouTrack for follow-ups to this issue. GitHub issues will be closed in the coming weeks.