-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix focus management for text fields #51009
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
When Safari auto-completes a field, it synthesizes an event that quacks like a DomKeyboardEvent, but it lacks the `shiftKey` property. This change makes the property nullable, and adjusts its use. (This only affects debug mode builds)
I've re-deployed a small testing app with a form to test autocomplete, here:
I think this now works similarly across all browsers, PTAL @mdebbar. |
external JSBoolean? get _shiftKey; | ||
bool? get shiftKey => _shiftKey?.toDart; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is unrelated to this PR, I can move it to a separate PR to keep this one small.
if (this is! SafariDesktopTextEditingStrategy) { | ||
// handleBlur causes Safari to reopen autofill dialogs after autofill, | ||
// so we don't attach the listener there. | ||
subscriptions.add(DomSubscription(activeDomElement, 'blur', handleBlur)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the handleBlur
function was causing trouble with autocomplete in Safari (refocusing the field). Is this maybe not needed anymore?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…150582) flutter/engine@dd37cef...dda82d9 2024-06-20 tarrinneal@gmail.com Update StandardMessageCodec.readValue to be @nullable (flutter/engine#53473) 2024-06-20 bruno.leroux@gmail.com [Web] Fix extra new line when inputAction is not newline for a multilâ�¦ (flutter/engine#53453) 2024-06-20 skia-flutter-autoroll@skia.org Roll Dart SDK from 366eb1b4b308 to be6b533e07e7 (1 revision) (flutter/engine#53492) 2024-06-20 tugorez@users.noreply.github.com Fix focus management for text fields (flutter/engine#51009) 2024-06-20 skia-flutter-autoroll@skia.org Roll Dart SDK from cbd933e707e7 to 366eb1b4b308 (1 revision) (flutter/engine#53487) 2024-06-20 skia-flutter-autoroll@skia.org Roll Skia from 17626ca22729 to 4471ee07e223 (1 revision) (flutter/engine#53486) 2024-06-20 skia-flutter-autoroll@skia.org Roll Dart SDK from e403519a4436 to cbd933e707e7 (1 revision) (flutter/engine#53485) 2024-06-20 skia-flutter-autoroll@skia.org Roll Skia from 4acebac47ea5 to 17626ca22729 (1 revision) (flutter/engine#53484) 2024-06-20 skia-flutter-autoroll@skia.org Roll Skia from 199e1a49b091 to 4acebac47ea5 (1 revision) (flutter/engine#53482) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Reason for revert: This causes b/348598454. We're getting test failures with stack traces like the following after this PR:
which seems related to the focus changes in this PR. |
This reverts commit 87a632b.
Reverts: #51009 Initiated by: jiahaog Reason for reverting: This causes b/348598454. We're getting test failures with stack traces like the following after this PR: ``` Cannot get renderObject of inactive element. In order for an element to have a valid renderObject, it must be active, which means it is part of the tree. Instead, this element is in the _ElementLifecycle.inactive state. If you called this method from a State object, consider guarding ``` Original PR Author: tugorez Reviewed By: {mdebbar} This change reverts the following previous change: Fix focus management for text fields This PR: 1. Refactors the DOM `focus` function to take [options][1] 2. Removes the timers sorrounding the `activeDomElement.focus()` so that the input elements get focused as immediate as possible. 3. Prevents the default on pointerdown in a Flutter View and schedules a `requestViewFocusChange` to claim focus in that view after some time. This gives `2` the opportunity to focus the right `<input />` or `<textarea />` element. This helps focus correctly transition from one input element to another (without jumping to a flutter view in between). 4. Deactivating a `TextField` doesn't blur the focused element anymore, it insteads schedules for later a call to move the focus to the flutter view if nothing inside it claimed focus first. 5. Prevents scroll in all the focus calls (this should help with the view jumping when focusing one text field after another). ## Sample apps 1. Full screen mode: https://tugorez.com/flutter_focus_web 2. Embedded mode: https://tugorez.com/flutter_focus_web?embedded [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
@gspencergoog is there something we're missing on the framework? |
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will take a look!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This reverts commit cf3ac2d (flutter#53502).
Relands: [**Fix focus management for text fields** (#51009)](#51009) by: * Reverting commit: cf3ac2d (#53502). * Keeping the new `ViewFocusBinding` disabled, as [suggested](#51009 (comment)). [C++, Objective-C, Java style guides]: https://github.com/flutter/engine/blob/main/CONTRIBUTING.md#style
…lutter#150582) flutter/engine@dd37cef...dda82d9 2024-06-20 tarrinneal@gmail.com Update StandardMessageCodec.readValue to be @nullable (flutter/engine#53473) 2024-06-20 bruno.leroux@gmail.com [Web] Fix extra new line when inputAction is not newline for a multilâ�¦ (flutter/engine#53453) 2024-06-20 skia-flutter-autoroll@skia.org Roll Dart SDK from 366eb1b4b308 to be6b533e07e7 (1 revision) (flutter/engine#53492) 2024-06-20 tugorez@users.noreply.github.com Fix focus management for text fields (flutter/engine#51009) 2024-06-20 skia-flutter-autoroll@skia.org Roll Dart SDK from cbd933e707e7 to 366eb1b4b308 (1 revision) (flutter/engine#53487) 2024-06-20 skia-flutter-autoroll@skia.org Roll Skia from 17626ca22729 to 4471ee07e223 (1 revision) (flutter/engine#53486) 2024-06-20 skia-flutter-autoroll@skia.org Roll Dart SDK from e403519a4436 to cbd933e707e7 (1 revision) (flutter/engine#53485) 2024-06-20 skia-flutter-autoroll@skia.org Roll Skia from 4acebac47ea5 to 17626ca22729 (1 revision) (flutter/engine#53484) 2024-06-20 skia-flutter-autoroll@skia.org Roll Skia from 199e1a49b091 to 4acebac47ea5 (1 revision) (flutter/engine#53482) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll Please CC jsimmons@google.com,rmistry@google.com,zra@google.com on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Fix focus management for text fields
This PR:
focus
function to take optionsactiveDomElement.focus()
so that the input elements get focused as immediate as possible.requestViewFocusChange
to claim focus in that view after some time. This gives2
the opportunity to focus the right<input />
or<textarea />
element. This helps focus correctly transition from one input element to another (without jumping to a flutter view in between).TextField
doesn't blur the focused element anymore, it insteads schedules for later a call to move the focus to the flutter view if nothing inside it claimed focus first.Sample apps
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.