Keep focus when tapping within IgnoreKeyboardDismiss - #192
Conversation
A focused TextField unfocuses itself on taps outside its own TapRegion. That happens on pointer down, before IgnoreKeyboardDismiss sets ignoreNextTap, and independently of it, so the widget had no effect against that path. Only mobile targets receiving touch input were spared. The default tap-outside action unfocuses for every pointer kind on desktop targets, and for everything but touch on mobile, leaving nine of the twelve platform and pointer-kind combinations broken. Joining the text field's tap region opts the subtree out of that path. Resolves MisterJimson#184.
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #192 +/- ##
===========================================
+ Coverage 76.53% 89.24% +12.71%
===========================================
Files 6 6
Lines 98 93 -5
===========================================
+ Hits 75 83 +8
+ Misses 23 10 -13
🚀 New features to boost your workflow:
|
MisterJimson
left a comment
There was a problem hiding this comment.
Reviewed after updating onto current master. The focused regression tests pass, all analysis jobs pass, and Android/iOS/macOS/JavaScript/Wasm builds pass. The six publish dry-run jobs are failing because Flutter 3.47.1 rewrites checked-in analysis_options files before package validation; that is repository CI maintenance unrelated to this two-file change.
Resolves #184.
IgnoreKeyboardDismisshad no effect against theTextField's own dismissal. The reported case was mouse input, but the underlying problem is broader — see the table below.Cause
Not the
ignoreNextTaphandshake, which fires in the correct order for every pointer kind.EditableTextwraps its field in aTapRegionand unfocuses on a tap outside it. That runs on pointer down, beforeIgnoreKeyboardDismisssets the flag, and independently of it.The default tap-outside action unfocuses unconditionally on desktop targets, and for every kind except touch on mobile. Measured against
IgnoreKeyboardDismissbefore this change:Fix
Wrap in
TextFieldTapRegion, joining theEditableTexttap-region group so taps inside the subtree are no longer "outside" the field. The existing flag still covers dismissals originating fromKeyboardDismissOnTapitself, sodismissOnCapturedTapsbehaviour is unchanged.Tests
Two tests in the
KeyboardDismissOnTapgroup, run underTargetPlatformVariant.all(). Nine of the twelve resulting cases fail without the change; the three that pass (touch on mobile targets) guard the previously-working path.Also verified manually that an interactive child still works as intended — an
ElevatedButtonwrapped inIgnoreKeyboardDismissfiresonPressedand keeps focus for both pointer kinds, and a tap on an unrelated widget still dismisses.