Skip to content

Commit c5e31af

Browse files
nturgutgspencergoog
nturgut
authored andcommitted
fixing the autofill overlay problem (blue area for chrome) (flutter#21610)
* fixing the autofill overlay problem (blue area for chrome) * addression comments
1 parent 59f43cd commit c5e31af

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

lib/web_ui/lib/src/engine/dom_renderer.dart

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,21 @@ flt-glass-pane * {
307307
''', sheet.cssRules.length);
308308
}
309309

310+
// This css prevents an autofill overlay brought by the browser during
311+
// text field autofill by delaying the transition effect.
312+
// See: https://github.com/flutter/flutter/issues/61132.
313+
if(browserHasAutofillOverlay()) {
314+
sheet.insertRule('''
315+
.transparentTextEditing:-webkit-autofill,
316+
.transparentTextEditing:-webkit-autofill:hover,
317+
.transparentTextEditing:-webkit-autofill:focus,
318+
.transparentTextEditing:-webkit-autofill:active {
319+
-webkit-transition-delay: 99999s;
320+
}
321+
''', sheet.cssRules.length);
322+
}
323+
324+
310325
final html.BodyElement bodyElement = html.document.body!;
311326
setElementStyle(bodyElement, 'position', 'fixed');
312327
setElementStyle(bodyElement, 'top', '0');

lib/web_ui/lib/src/engine/text_editing/text_editing.dart

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,16 @@ bool _debugVisibleTextEditing = false;
1111
/// The `keyCode` of the "Enter" key.
1212
const int _kReturnKeyCode = 13;
1313

14+
/// Blink and Webkit engines, bring an overlay on top of the text field when it
15+
/// is autofilled.
16+
bool browserHasAutofillOverlay() =>
17+
browserEngine == BrowserEngine.blink ||
18+
browserEngine == BrowserEngine.webkit;
19+
20+
/// `transparentTextEditing` class is configured to make the autofill overlay
21+
/// transparent.
22+
const String transparentTextEditingClass = 'transparentTextEditing';
23+
1424
void _emptyCallback(dynamic _) {}
1525

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

42-
/// This property makes the input's blinking cursor transparent.
52+
if (browserHasAutofillOverlay()) {
53+
domElement.classes.add(transparentTextEditingClass);
54+
}
55+
56+
// This property makes the input's blinking cursor transparent.
4357
elementStyle.setProperty('caret-color', 'transparent');
4458

4559
if (_debugVisibleTextEditing) {
@@ -80,6 +94,10 @@ void _hideAutofillElements(html.HtmlElement domElement,
8094
..left = '-9999px';
8195
}
8296

97+
if (browserHasAutofillOverlay()) {
98+
domElement.classes.add(transparentTextEditingClass);
99+
}
100+
83101
/// This property makes the input's blinking cursor transparent.
84102
elementStyle.setProperty('caret-color', 'transparent');
85103
}

lib/web_ui/test/text_editing_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,18 @@ void testMain() {
13431343
'500 12px sans-serif',
13441344
);
13451345

1346+
// For `blink` and `webkit` browser engines the overlay would be hidden.
1347+
if (browserEngine == BrowserEngine.blink ||
1348+
browserEngine == BrowserEngine.webkit) {
1349+
expect(textEditing.editingElement.domElement.classes,
1350+
contains('transparentTextEditing'));
1351+
} else {
1352+
expect(
1353+
textEditing.editingElement.domElement.classes.any(
1354+
(element) => element.toString() == 'transparentTextEditing'),
1355+
isFalse);
1356+
}
1357+
13461358
const MethodCall clearClient = MethodCall('TextInput.clearClient');
13471359
sendFrameworkMessage(codec.encodeMethodCall(clearClient));
13481360
},
@@ -1806,6 +1818,17 @@ void testMain() {
18061818
final CssStyleDeclaration css = firstElement.style;
18071819
expect(css.color, 'transparent');
18081820
expect(css.backgroundColor, 'transparent');
1821+
1822+
// For `blink` and `webkit` browser engines the overlay would be hidden.
1823+
if (browserEngine == BrowserEngine.blink ||
1824+
browserEngine == BrowserEngine.webkit) {
1825+
expect(firstElement.classes, contains('transparentTextEditing'));
1826+
} else {
1827+
expect(
1828+
firstElement.classes.any(
1829+
(element) => element.toString() == 'transparentTextEditing'),
1830+
isFalse);
1831+
}
18091832
});
18101833

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

0 commit comments

Comments
 (0)