[Web text input] Make placeholder invisible (flutter/engine#28494)

This commit is contained in:
LongCatIsLooong
2021-09-10 14:17:01 -07:00
committed by GitHub
parent c8d9efb21a
commit 971b0f4d9a
2 changed files with 65 additions and 29 deletions

View File

@@ -703,18 +703,22 @@ void applyGlobalCssRulesToSheet(
// This undoes browser's default painting and layout attributes of range
// input, which is used in semantics.
sheet.insertRule('''
flt-semantics input[type=range] {
appearance: none;
-webkit-appearance: none;
width: 100%;
position: absolute;
border: none;
top: 0;
right: 0;
bottom: 0;
left: 0;
}''', sheet.cssRules.length);
sheet.insertRule(
'''
flt-semantics input[type=range] {
appearance: none;
-webkit-appearance: none;
width: 100%;
position: absolute;
border: none;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
''',
sheet.cssRules.length,
);
if (isWebKit) {
sheet.insertRule(
@@ -751,35 +755,45 @@ left: 0;
sheet.cssRules.length);
}
sheet.insertRule('''
flt-semantics input,
flt-semantics textarea,
flt-semantics [contentEditable="true"] {
caret-color: transparent;
}
''', sheet.cssRules.length);
flt-semantics input,
flt-semantics textarea,
flt-semantics [contentEditable="true"] {
caret-color: transparent;
}
''', sheet.cssRules.length);
// By default on iOS, Safari would highlight the element that's being tapped
// on using gray background. This CSS rule disables that.
if (isWebKit) {
sheet.insertRule('''
$glassPaneTagName * {
-webkit-tap-highlight-color: transparent;
}
''', sheet.cssRules.length);
$glassPaneTagName * {
-webkit-tap-highlight-color: transparent;
}
''', sheet.cssRules.length);
}
// Hide placeholder text
sheet.insertRule(
'''
.flt-text-editing::placeholder {
opacity: 0;
}
''',
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;
}
''', sheet.cssRules.length);
.transparentTextEditing:-webkit-autofill,
.transparentTextEditing:-webkit-autofill:hover,
.transparentTextEditing:-webkit-autofill:focus,
.transparentTextEditing:-webkit-autofill:active {
-webkit-transition-delay: 99999s;
}
''', sheet.cssRules.length);
}
}

View File

@@ -169,6 +169,28 @@ void testMain() {
renderer.removeResource(resource);
expect(resourceRoot.childNodes.length, 0);
});
test('hide placeholder text for textfield', () {
final DomRenderer renderer = DomRenderer();
final html.InputElement regularTextField = html.InputElement();
regularTextField.placeholder = 'Now you see me';
renderer.addResource(regularTextField);
renderer.focus(regularTextField);
html.CssStyleDeclaration? style = renderer.glassPaneShadow?.querySelector('input')?.getComputedStyle('::placeholder');
expect(style, isNotNull);
expect(style?.opacity, isNot('0'));
final html.InputElement textField = html.InputElement();
textField.placeholder = 'Now you dont';
renderer.addElementClass(textField, 'flt-text-editing');
renderer.addResource(textField);
renderer.focus(textField);
style = renderer.glassPaneShadow?.querySelector('input.flt-text-editing')?.getComputedStyle('::placeholder');
expect(style, isNotNull);
expect(style?.opacity, '0');
}, skip: browserEngine != BrowserEngine.firefox);
}
@JS('Element.prototype.attachShadow')