From f0e2596c5c30ab3ba6cc7744d83d4f7bcaba47bb Mon Sep 17 00:00:00 2001
From: Hassan <110993981+htoor3@users.noreply.github.com>
Date: Fri, 26 May 2023 11:17:18 -0500
Subject: [PATCH] [web] - Fix autofill group input ordering
(flutter/engine#42268)
Ordering of input elements inside of the DOM tree for autofill groups does not reflect the order of the form rendered on screen. This is causing some issues with password managers and autofill, specifically Bitwarden.
We are currently always appending the currently focused input element to the end of the form.
This leads to a tree that appears out of order:
This fix is tracking the position of where the focused input node should be inserted and inserting it there, rather than always at the end of the form. Once the tree is ordered correctly, Bitwarden's autofill logic works in Flutter forms.
Tree order after fix:
Fixes https://github.com/flutter/flutter/issues/61301
---
.../src/engine/text_editing/text_editing.dart | 22 +++++++++-
.../web_ui/test/engine/text_editing_test.dart | 41 +++++++++++++++++++
2 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
index d0ad3a28183..49746c9245e 100644
--- a/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
+++ b/engine/src/flutter/lib/web_ui/lib/src/engine/text_editing/text_editing.dart
@@ -145,6 +145,7 @@ class EngineAutofillForm {
this.elements,
this.items,
this.formIdentifier = '',
+ this.insertionReferenceNode,
});
final DomHTMLFormElement formElement;
@@ -153,6 +154,7 @@ class EngineAutofillForm {
final Map? items;
+ final DomHTMLElement? insertionReferenceNode;
/// Identifier for the form.
///
/// It is constructed by concatenating unique ids of input elements on the
@@ -189,6 +191,7 @@ class EngineAutofillForm {
final Map elements = {};
final Map items = {};
final DomHTMLFormElement formElement = createDomHTMLFormElement();
+ DomHTMLElement? insertionReferenceNode;
// Validation is in the framework side.
formElement.noValidate = true;
@@ -209,6 +212,7 @@ class EngineAutofillForm {
AutofillInfo.fromFrameworkMessage(focusedElementAutofill);
if (fields != null) {
+ bool fieldIsFocusedElement = false;
for (final Map field in
fields.cast