-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
First focusable Compose component doesn't get focus in IDE toolwindow #3888
First focusable Compose component doesn't get focus in IDE toolwindow #3888
Comments
Does it work if you request focus on the
|
Yep, that's the current workaround in the Jewel IDE sample. It isn't good enough tho; you can either only ever do it the first time a tab is shown (with a |
I don't think this is an issue specific to |
The problem I reported here is that when the ComposePanel gets focused (it is never destroyed when not visible, to be clear), it doesn't pass the focus inwards to its content. This is the issue, and not how to save/restore focus, which is not necessary in this case. It is not a "holding it wrong" problem, as far as I can tell. Nikolay was aware of this issue before moving out of the team and may have further information about the internals, but he did validate this as a ComposePanel issue. |
But it does (see code below); it's just that Compose does not automatically focus anything. If you open a regular Compose application (without Here is a
|
Maybe I am not explaining myself clearly enough, so let me try again. First things first: I think it is reasonable to expect that when a ComposePanel gets focus for the first time, and it contains focusable composables, it will pass the focus inwards to the first focusable composable. This is because:
With that out of way, let's look at what's happening here. I have created the most minimal reproducer I can think of: a JTabbedPane with a ComposePanel (no external dependencies), and a JPanel, each having three buttons. You can find the reproducer code here: https://github.com/rock3r/cfd-repros/blob/main/src/main/kotlin/TabbedUI.kt
|
Again, to be extra clear: I am ok with whatever is the first focusable component in the ComposePanel getting the focus. I am not asking to save which composable specifically has the focus, and restoring it (although there is no sane way to do that with the current focus APIs, that is a different discussion and not one that is important here) |
This is true in Swing, but isn't true in Compose. I agree it's reasonable to expect, but it's just not true. However, it appears that When I run the reproducer you linked to (in When I switch to the Swing tab and back, however, the "First button" is no longer focused. This is because the cause of the focus event in this case is, for some reason,
the "First button" receives focus correctly again. It appears that
I don't exactly know why |
Thanks for the in-depth analysis, Sasha. I am not sure why the cause is set to UNKNOWN, but that's probably because it's a programmatic change (the JTabbedPane does it on tab change, I reckon). It'd be great to at least sort out that case. |
By the way, in your reproducer, |
Ah, yep — just a leftover from a previous iteration that also had focusable. Thanks for pointing it out tho — it's an easy mistake to make. |
Describe the bug
When working in the IDE, if I have a ToolWindow with a ComposePanel as its tab content, when the tab is shown, the focus is not passed to the first focusable Composable, even though the ComposePanel does get focused.
Affected platforms
Select one of the platforms below:
Versions
To Reproduce
Create an IJ plugin using Jewel. Add a toolwindow and add Compose content to it.
Expected behavior
The first composable component should get focused when the composition starts.
Screenshots
Additional context
@Walingar can provide it
The text was updated successfully, but these errors were encountered: