Skip to content

Make canvas focused when Compose handles pointer events#2796

Merged
Oleksandr Karpovich (eymar) merged 1 commit into
jb-mainfrom
ok/fix_canvas_focus
Feb 26, 2026
Merged

Make canvas focused when Compose handles pointer events#2796
Oleksandr Karpovich (eymar) merged 1 commit into
jb-mainfrom
ok/fix_canvas_focus

Conversation

@eymar

@eymar Oleksandr Karpovich (eymar) commented Feb 25, 2026

Copy link
Copy Markdown
Member

Fixes https://youtrack.jetbrains.com/issue/CMP-9797

In 8d814d7 we started to preventDefault mouse events processed by Compose. preventDefault prevents a browser from focusing the canvas - that's why ESC stopped working.

Fixes https://youtrack.jetbrains.com/issue/CMP-9797/Web-Dialogs-Popups-dont-close-on-the-first-attempt-when-pressing-Esc

Testing

This should be tested by QA

Release Notes

Fixes - Web

  • (prerelease fix) Make canvas focused so it receives key events (e.g. ESC)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried (because we introduce more logic rather then reduce logic) but failed to come up with scenario where this breaks )

@eymar Oleksandr Karpovich (eymar) merged commit c31fceb into jb-main Feb 26, 2026
17 of 18 checks passed
@eymar Oleksandr Karpovich (eymar) deleted the ok/fix_canvas_focus branch February 26, 2026 17:36
Comment on lines +444 to 454
addTypedEvent<FocusEvent>("focus") { event ->
canvasFocused = true
}

addTypedEvent<FocusEvent>("blur") { event ->
canvasFocused = false
}

state.globalEvents.addDisposableEvent("focus") {
archComponentsOwner.lifecycle.handleLifecycleEvent(Lifecycle.Event.ON_RESUME)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why don't you use already existing listeners?

@eymar Oleksandr Karpovich (eymar) Mar 2, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean state.globalEvents.addDisposableEvent("focus") ?

The global listener is listening on the window. But addTypedEvent<FocusEvent>("focus") adds a listener to the canvas.

In this case I need to know if a canvas is focused or not.

// iOS Safari doesn't request focus when the page is shown,
// and the lifecycle doesn't trigger ON_RESUME.
// so, we decided to handle every touch
archComponentsOwner.lifecycle.currentState = Lifecycle.State.RESUMED

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't forget to handle this as well

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean to handle Touch Events?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean Safari doesn't requests focus sometimes

Konstantin (terrakok) added a commit that referenced this pull request Mar 13, 2026
ApoloApps pushed a commit to ApoloApps/compose-multiplatform-core that referenced this pull request Mar 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants