[web] Hide autofill overlay (flutter/engine#39294)

* Make autofill styling transparent

* Formatting

* Add tests

* Modify tests

* Add correct prefix for safari and firefox tests
This commit is contained in:
htoor3
2023-02-02 09:59:06 -06:00
committed by GitHub
parent ae70d40faf
commit ab3e814000
2 changed files with 29 additions and 4 deletions

View File

@@ -317,16 +317,16 @@ void applyGlobalCssRulesToSheet(
}
''', 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.
// This CSS makes the autofill overlay transparent in order to prevent it
// from overlaying on top of Flutter-rendered text inputs.
// See: https://github.com/flutter/flutter/issues/118337.
if (browserHasAutofillOverlay()) {
sheet.insertRule('''
$cssSelectorPrefix .transparentTextEditing:-webkit-autofill,
$cssSelectorPrefix .transparentTextEditing:-webkit-autofill:hover,
$cssSelectorPrefix .transparentTextEditing:-webkit-autofill:focus,
$cssSelectorPrefix .transparentTextEditing:-webkit-autofill:active {
-webkit-transition-delay: 99999s;
opacity: 0 !important;
}
''', sheet.cssRules.length);
}

View File

@@ -112,6 +112,31 @@ void testMain() {
expect(hidesRevealIcons, isFalse);
}, skip: isEdge);
test(
'Attaches styles to hide the autofill overlay for browsers that support it',
() {
final DomElement? style =
hostNode.querySelector('#flt-internals-stylesheet');
final String vendorPrefix = (isSafari || isFirefox) ? '' : '-webkit-';
final bool autofillOverlay = hasCssRule(style,
selector: '.transparentTextEditing:${vendorPrefix}autofill',
declaration: 'opacity: 0 !important');
final bool autofillOverlayHovered = hasCssRule(style,
selector: '.transparentTextEditing:${vendorPrefix}autofill:hover',
declaration: 'opacity: 0 !important');
final bool autofillOverlayFocused = hasCssRule(style,
selector: '.transparentTextEditing:${vendorPrefix}autofill:focus',
declaration: 'opacity: 0 !important');
final bool autofillOverlayActive = hasCssRule(style,
selector: '.transparentTextEditing:${vendorPrefix}autofill:active',
declaration: 'opacity: 0 !important');
expect(autofillOverlay, isTrue);
expect(autofillOverlayHovered, isTrue);
expect(autofillOverlayFocused, isTrue);
expect(autofillOverlayActive, isTrue);
}, skip: !browserHasAutofillOverlay());
_runDomTests(hostNode);
});