Repository navigation
A finger's tap on a control in a sheet a field's focus raised reaches the control - #12
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On a touch screen, the first tap on a button in a narrow sheet whose field has the focus does nothing. A mouse click on a touch-screen device does the same. The second tap works. An app hits this with a sheet that pushes a page with an autofocused field: a menu sheet pushing "Open a case", say. The first tap on Back, Close or the submit button is lost.
A focused field raises the sheet to the tallest height, through neutral.css's
@media (any-pointer: coarse)rule ([data-exact-detent]:has(… :focus)), the way the keyboard does on iOS. A tap (through its compatibilitymousedown) or a mouse press sends amousedown, and Chrome moves the focus to the button there. The field blurs, the:has(:focus)rule stops matching, and the sheet drops back to its detent before theclick. The control is no longer under the finger, so theclickgoes to an ancestor.Solution
navigation.connectadds a capturemousedownlistener. When the focused field is in a route with a detent, the target is in that same route, and the window is where the raise applies, it callspreventDefault(). The field keeps the focus, the sheet stays raised, and theclickreaches the control. UIKit behaves the same way: tapping a control doesn't resign the first responder, so the keyboard stays up.It only applies while the raise can apply: a narrow window on a device with a coarse pointer (
any-pointer: coarse), so a mouse on a touch screen is covered too. A press on another field, aselector alabel, a sheet without a detent, and a window outside the raise's media query all behave as before.Test plan
host/web/tests/sheet-detent.test.mjs: a new case focuses a field in a route pushed inside amedium largesheet, under Chrome's touch emulation at 390×844, then taps a button below it withInput.dispatchTouchEventand clicks it withInput.dispatchMouseEvent. With the fix the button gets each click, the field keeps the focus, and the sheet stays at the tallest. Without it, the click lands on the stack'snavand the sheet drops to 428 / 416. All 10 cases pass.bun scripts/caps.mjspasses.prefer hover none) to 64 passed, 0 failed.focus,js-autofocus,prevent-focus,route-focus,route-pages,sheet-ids,tree-routesandnavigation-diagnosticshave the same 63 passes and the same 10 failures with and without this change. The failures are Firefox and WebKit cases plus wasm/js cases that need builds I don't have here.