Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus the first item at the start #4917

Open
igordmn opened this issue Jun 3, 2024 · 8 comments
Open

Focus the first item at the start #4917

igordmn opened this issue Jun 3, 2024 · 8 comments
Assignees
Labels
enhancement New feature or request focus management p:high High priority

Comments

@igordmn
Copy link
Collaborator

igordmn commented Jun 3, 2024

When we:

  • start a window, a dialog or popup, focus the first.
  • call focusManager.clearFocus
    we 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

@igordmn igordmn added enhancement New feature or request focus management labels Jun 3, 2024
@igordmn igordmn self-assigned this Jun 3, 2024
@m-sasha
Copy link
Contributor

m-sasha commented Jun 3, 2024

Welcome change, but it is a breaking one...

@igordmn igordmn added the p:high High priority label Jun 3, 2024
@igordmn
Copy link
Collaborator Author

igordmn commented Jun 3, 2024

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)

@igordmn
Copy link
Collaborator Author

igordmn commented Jun 3, 2024

After JetBrains/compose-multiplatform-core#1352, it already works for ComposePanel

@m-sasha
Copy link
Contributor

m-sasha commented Jun 3, 2024

Right, but there one could think of it as making ComposePanel behave as a proper Swing widget, where initial selection is the norm.

igordmn added a commit to JetBrains/compose-multiplatform-core that referenced this issue Jun 7, 2024
No need to apply them anymore.

```
git diff androidx/compose-ui/1.6.7 origin/jb-main -- compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/focus/FocusOwnerImpl.kt > 1.patch
```

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-1212/Integration.-Check-changes-in-FocusOwnerImpl

JetBrains/compose-multiplatform#4917

Make the first ComposeComponent focused initially

Apply jb-main FocusOwnerImpl.kt changes

No need to apply them anymore.

```
git diff androidx/compose-ui/1.6.7 origin/jb-main -- compose/ui/ui/src/commonMain/kotlin/androidx/compose/ui/focus/FocusOwnerImpl.kt > 1.patch
```

Fixes https://youtrack.jetbrains.com/issue/COMPOSE-1212/Integration.-Check-changes-in-FocusOwnerImpl

Fixes JetBrains/compose-multiplatform#4919

JetBrains/compose-multiplatform#4917

JetBrains/compose-multiplatform#2944
@igordmn
Copy link
Collaborator Author

igordmn commented Jun 7, 2024

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

@iamcalledrob
Copy link

+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.

@iamcalledrob
Copy link

iamcalledrob commented Jul 4, 2024

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.

@igordmn
Copy link
Collaborator Author

igordmn commented Jul 4, 2024

Your issue is solvable using #4764 (comment) (answered in Slack)

This enhancement won't solve it, as if there is no focusable elements, there will be no focus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request focus management p:high High priority
Projects
None yet
Development

No branches or pull requests

3 participants