Skip to content

Cancel touch event if active backing DOM field is detected#2996

Merged
Shagen Ogandzhanian (Schahen) merged 1 commit into
jb-mainfrom
sh/CMP-10079-web-ios26.4-minimal-fix
Apr 22, 2026
Merged

Cancel touch event if active backing DOM field is detected#2996
Shagen Ogandzhanian (Schahen) merged 1 commit into
jb-mainfrom
sh/CMP-10079-web-ios26.4-minimal-fix

Conversation

@Schahen

@Schahen Shagen Ogandzhanian (Schahen) commented Apr 21, 2026

Copy link
Copy Markdown

Following changes are introduced:

  • we treat stylus as touch event rather then mouse one
  • somer redundant code was removed
  • additional touchevent introduced that checks whether whether an active backing dom input is detected - in that case we preventDefault

Testing

./gradlew testWeb + manual

Release Notes

Fixes - Web

  • [iOS] Fix virtual keyboard jumps after each tap. iOS 26.4 only.

@Schahen Shagen Ogandzhanian (Schahen) changed the title Cancel touch event if active bacjing dom field is detected Cancel touch event if active backing DOM field is detected Apr 21, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Addresses iOS web keyboard “jumping” by cancelling native touch interactions when a DOM backing input is currently focused, and aligns pointer-type handling so stylus (“pen”) is treated as touch rather than mouse.

Changes:

  • Add a touchstart listener that calls preventDefault() when a focused backing DOM input is detected (CMP-10079).
  • Route pointer events through a mouse vs non-mouse split (pointerType === 'mouse'), implicitly treating “pen” as touch.
  • Remove/clean up redundant web input-related code and update the DnD demo to include a draggable TextField.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
compose/ui/ui/src/webMain/kotlin/androidx/compose/ui/window/ComposeWindowInternal.web.kt Adds touchstart cancellation when backing input is focused; updates pointer-type branching; adds focus detection helper.
compose/ui/ui/src/webMain/kotlin/androidx/compose/ui/platform/DomInputStrategy.kt Removes an unused blur listener stub.
compose/ui/ui/src/webMain/kotlin/androidx/compose/ui/platform/BackingDomInput.kt Simplifies the “focus twice” logic for the backing element.
compose/mpp/demo/src/webMain/kotlin/androidx/compose/mpp/demo/components/DragAndDropExample.web.kt Extends demo with a draggable TextField whose text is used as DnD payload.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


addTypedEvent<TouchEvent>("touchstart") { evt ->
// in most cases we don't care about touches since in Compose we do not process them at all
// there's one case however when we need to cancel them - it's when we are focussed in a DOM backing field

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

The comment uses "focussed"; project terminology elsewhere uses "focused" (and it’s the more common spelling). Consider updating to avoid inconsistent spelling in docs/comments.

Suggested change
// there's one case however when we need to cancel them - it's when we are focussed in a DOM backing field
// there's one case however when we need to cancel them - it's when we are focused in a DOM backing field

Copilot uses AI. Check for mistakes.
Comment on lines +390 to +399
addTypedEvent<TouchEvent>("touchstart") { evt ->
// in most cases we don't care about touches since in Compose we do not process them at all
// there's one case however when we need to cancel them - it's when we are focussed in a DOM backing field
// see https://youtrack.jetbrains.com/issue/CMP-10079

val backingInput = (platformContext.textInputService as WebTextInputService).getBackingInput()
if (backingInput?.isFocused() == true) {
evt.preventDefault()
}
}

Copilot AI Apr 21, 2026

Copy link

Choose a reason for hiding this comment

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

New behavior cancels native touchstart when a backing DOM input is focused. There are existing web tests around pointer/keyboard preventDefault behavior, but nothing covering this touchstart-specific path (or stylus/pen being treated as touch). Please add a web test that dispatches a touchstart while the backing input is focused and asserts the event is defaultPrevented (and ideally cover pointerType="pen" routing into the touch path).

Copilot uses AI. Check for mistakes.
@Schahen Shagen Ogandzhanian (Schahen) merged commit 310bfb3 into jb-main Apr 22, 2026
21 of 22 checks passed
@Schahen Shagen Ogandzhanian (Schahen) deleted the sh/CMP-10079-web-ios26.4-minimal-fix branch April 22, 2026 12:24
Ekaterina Zaitseva (sekater) added a commit that referenced this pull request Apr 24, 2026
…3013)

This is cherry-pick of 310bfb3

## Testing
manual 

## Release Notes
### Fixes - Web
- [CMP-10102](https://youtrack.jetbrains.com/issue/CMP-10102) [Web]
Safari. DragAndDrop. After performing drag and drop operations buttons
are unclickable on the first attempt
Sajid Ali (sajidalidev) pushed a commit to sajidalidev/compose-multiplatform-core-tvos that referenced this pull request May 6, 2026
…#2996)

Following changes are introduced:
  - we treat stylus as touch event rather then mouse one
  - somer redundant code was removed
- additional touchevent introduced that checks whether whether an active
backing dom input is detected - in that case we preventDefault

`./gradlew testWeb` + manual

- [CMP-10079](https://youtrack.jetbrains.com/issue/CMP-10079) [Web]
Mobile. iOS 26.4 only. The virtual keyboard jumps after each tap
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