Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/web_ui/lib/src/engine/dom_renderer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,21 @@ flt-glass-pane * {
''', sheet.cssRules.length);
}

// This css prevents an autofill overlay brought by the browser during
// text field autofill by delaying the transition effect.
// See: https://github.com/flutter/flutter/issues/61132.
if(browserHasAutofillOverlay()) {
sheet.insertRule('''
.transparentTextEditing:-webkit-autofill,
.transparentTextEditing:-webkit-autofill:hover,
.transparentTextEditing:-webkit-autofill:focus,
.transparentTextEditing:-webkit-autofill:active {
-webkit-transition-delay: 99999s;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add comment above this block describing issue, also transition-delay.

}
''', sheet.cssRules.length);
}


final html.BodyElement bodyElement = html.document.body!;
setElementStyle(bodyElement, 'position', 'fixed');
setElementStyle(bodyElement, 'top', '0');
Expand Down
20 changes: 19 additions & 1 deletion lib/web_ui/lib/src/engine/text_editing/text_editing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ bool _debugVisibleTextEditing = false;
/// The `keyCode` of the "Enter" key.
const int _kReturnKeyCode = 13;

/// Blink and Webkit engines, bring an overlay on top of the text field when it
/// is autofilled.
bool browserHasAutofillOverlay() =>
browserEngine == BrowserEngine.blink ||
browserEngine == BrowserEngine.webkit;

/// `transparentTextEditing` class is configured to make the autofill overlay
/// transparent.
const String transparentTextEditingClass = 'transparentTextEditing';

void _emptyCallback(dynamic _) {}

/// These style attributes are constant throughout the life time of an input
Expand Down Expand Up @@ -39,7 +49,11 @@ void _setStaticStyleAttributes(html.HtmlElement domElement) {
..overflow = 'hidden'
..transformOrigin = '0 0 0';

/// This property makes the input's blinking cursor transparent.
if (browserHasAutofillOverlay()) {
domElement.classes.add(transparentTextEditingClass);
}

// This property makes the input's blinking cursor transparent.
elementStyle.setProperty('caret-color', 'transparent');

if (_debugVisibleTextEditing) {
Expand Down Expand Up @@ -80,6 +94,10 @@ void _hideAutofillElements(html.HtmlElement domElement,
..left = '-9999px';
}

if (browserHasAutofillOverlay()) {
domElement.classes.add(transparentTextEditingClass);
}

/// This property makes the input's blinking cursor transparent.
elementStyle.setProperty('caret-color', 'transparent');
}
Expand Down
23 changes: 23 additions & 0 deletions lib/web_ui/test/text_editing_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,18 @@ void testMain() {
'500 12px sans-serif',
);

// For `blink` and `webkit` browser engines the overlay would be hidden.
if (browserEngine == BrowserEngine.blink ||
browserEngine == BrowserEngine.webkit) {
expect(textEditing.editingElement.domElement.classes,
contains('transparentTextEditing'));
} else {
expect(
textEditing.editingElement.domElement.classes.any(
(element) => element.toString() == 'transparentTextEditing'),
isFalse);
}

const MethodCall clearClient = MethodCall('TextInput.clearClient');
sendFrameworkMessage(codec.encodeMethodCall(clearClient));
},
Expand Down Expand Up @@ -1806,6 +1818,17 @@ void testMain() {
final CssStyleDeclaration css = firstElement.style;
expect(css.color, 'transparent');
expect(css.backgroundColor, 'transparent');

// For `blink` and `webkit` browser engines the overlay would be hidden.
if (browserEngine == BrowserEngine.blink ||
browserEngine == BrowserEngine.webkit) {
expect(firstElement.classes, contains('transparentTextEditing'));
} else {
expect(
firstElement.classes.any(
(element) => element.toString() == 'transparentTextEditing'),
isFalse);
}
});

test('validate multi element form ids sorted for form id', () {
Expand Down