-
Notifications
You must be signed in to change notification settings - Fork 6k
Fix focus management for text fields #51009
Changes from 28 commits
d2e4ccc
ea09d6e
edab1dc
8bbc206
ed2f851
78521ec
72d3956
7a6c596
11b7dae
df75938
edfdacf
7daf2a1
7e811da
c23c944
08ab966
8c99cb4
153eee4
e8cf8e8
5cf50ac
6f85439
e931fbc
d70596d
e5af604
e54f9ad
9a194d3
dca6a02
318a2dd
2a6c339
e35705e
39c5c8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,7 @@ final class ViewFocusBinding { | |
| /// | ||
| /// DO NOT rely on this bit as it will go away soon. You're warned :)! | ||
| @visibleForTesting | ||
| static bool isEnabled = false; | ||
| static bool isEnabled = true; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ditman we might want to reland these changes but with this one set to false. Not sure what's breaking on the framework side but don't think the rest of these changes is related.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will take a look!
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| final FlutterViewManager _viewManager; | ||
| final ui.ViewFocusChangeCallback _onViewFocusChange; | ||
|
|
@@ -51,7 +51,7 @@ final class ViewFocusBinding { | |
| if (state == ui.ViewFocusState.focused) { | ||
| // Only move the focus to the flutter view if nothing inside it is focused already. | ||
| if (viewId != _viewId(domDocument.activeElement)) { | ||
| viewElement?.focus(); | ||
| viewElement?.focus(preventScroll: true); | ||
| } | ||
| } else { | ||
| viewElement?.blur(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -982,6 +982,22 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { | |
| ); | ||
| _convertEventsToPointerData(data: pointerData, event: event, details: down); | ||
| _callback(event, pointerData); | ||
|
|
||
| if (event.target == _viewTarget) { | ||
| // Ensure smooth focus transitions between text fields within the Flutter view. | ||
| // Without preventing the default and this delay, the engine may not have fully | ||
| // rendered the next input element, leading to the focus incorrectly returning to | ||
| // the main Flutter view instead. | ||
| // A zero-length timer is sufficient in all tested browsers to achieve this. | ||
| event.preventDefault(); | ||
| Timer(Duration.zero, () { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be useful to comment on the choice of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PTAL
ditman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| EnginePlatformDispatcher.instance.requestViewFocusChange( | ||
| viewId: _view.viewId, | ||
| state: ui.ViewFocusState.focused, | ||
| direction: ui.ViewFocusDirection.undefined, | ||
| ); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| // Why `domWindow` you ask? See this fiddle: https://jsfiddle.net/ditman/7towxaqp | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.