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

Fix ComposePanel.requestFocus #1352

Merged
merged 1 commit into from
May 14, 2024
Merged

Conversation

m-sasha
Copy link

@m-sasha m-sasha commented May 9, 2024

ComposePanel.requestFocus does not currently work because the focus event delivered to contentComponent has a cause of UNKNOWN (or ACTIVATION, if called right when the window is shown for the first time), which is not handled.

This PR adds calling focusManager.moveFocus(FocusDirection.Enter) on these events.

Fixes JetBrains/compose-multiplatform#3888 (comment)

Testing

  • Tested manually on the reproducer provided in the bug report.
  • Added a unit test.

Also tested with

fun main() = SwingUtilities.invokeLater {
    val frame = JFrame()
    val button = JButton("Show Compose Panel")
    var composePanel: ComposePanel? = null

    fun addComposePanel() {
        val panel = ComposePanel()
        panel.setContent {
            var text by remember { mutableStateOf("") }
            TextField(
                value = text,
                onValueChange = { text = it },
            )
        }
        panel.size = Dimension(400, 200)
        panel.location = Point(0, 100)
        frame.contentPane.add(panel, BorderLayout.CENTER)
        composePanel = panel
    }

    button.addActionListener {
        if (composePanel == null)
            addComposePanel()
        else
            composePanel!!.isVisible = !composePanel!!.isVisible
        button.setText(if (composePanel!!.isVisible) "Hide ComposePanel" else "Show ComposePanel")
        if (composePanel!!.isVisible)
            composePanel!!.requestFocus()
    }
    frame.contentPane.add(button, BorderLayout.NORTH)
    frame.size = Dimension(400, 300)
    frame.isVisible = true
}

This could be tested by QA.

Release Notes

Fixes - Desktop

  • Fixed ComposePanel.requestFocus(), making it correctly assign focus to the first focusable child

@m-sasha m-sasha requested a review from igordmn May 9, 2024 16:07
@m-sasha m-sasha merged commit bf488a7 into jb-main May 14, 2024
6 checks passed
@m-sasha m-sasha deleted the m-sasha/fix-ComposePanel-requestFocus branch May 14, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants