Cancel touch event if active backing DOM field is detected#2996
Conversation
There was a problem hiding this comment.
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
touchstartlistener that callspreventDefault()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 |
There was a problem hiding this comment.
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.
| // 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 |
| 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() | ||
| } | ||
| } |
There was a problem hiding this comment.
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).
310bfb3
into
jb-main
…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
…#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
Following changes are introduced:
Testing
./gradlew testWeb+ manualRelease Notes
Fixes - Web