[web] Prevent (forced-colors: active) from making the invisible text fields visible (flutter/engine#37089)

This commit is contained in:
Mouad Debbar
2022-11-01 18:21:45 -04:00
committed by GitHub
parent 13d9c0f556
commit 5ca9d287ba
3 changed files with 38 additions and 4 deletions

View File

@@ -332,6 +332,7 @@ extension DomCSSStyleDeclarationExtension on DomCSSStyleDeclaration {
set right(String value) => setProperty('right', value);
set bottom(String value) => setProperty('bottom', value);
set backgroundColor(String value) => setProperty('background-color', value);
set caretColor(String value) => setProperty('caret-color', value);
set pointerEvents(String value) => setProperty('pointer-events', value);
set filter(String value) => setProperty('filter', value);
set zIndex(String value) => setProperty('z-index', value);
@@ -400,6 +401,7 @@ extension DomCSSStyleDeclarationExtension on DomCSSStyleDeclaration {
String get right => getPropertyValue('right');
String get bottom => getPropertyValue('bottom');
String get backgroundColor => getPropertyValue('background-color');
String get caretColor => getPropertyValue('caret-color');
String get pointerEvents => getPropertyValue('pointer-events');
String get filter => getPropertyValue('filter');
String get zIndex => getPropertyValue('z-index');

View File

@@ -59,6 +59,9 @@ void _setStaticStyleAttributes(DomHTMLElement domElement) {
final DomCSSStyleDeclaration elementStyle = domElement.style;
elementStyle
// Prevent (forced-colors: active) from making our invisible text fields visible.
// For more details, see: https://developer.mozilla.org/en-US/docs/Web/CSS/forced-color-adjust
..setProperty('forced-color-adjust', 'none')
..whiteSpace = 'pre-wrap'
..alignContent = 'center'
..position = 'absolute'
@@ -69,10 +72,12 @@ void _setStaticStyleAttributes(DomHTMLElement domElement) {
..color = 'transparent'
..backgroundColor = 'transparent'
..background = 'transparent'
// This property makes the input's blinking cursor transparent.
..caretColor = 'transparent'
..outline = 'none'
..border = 'none'
..resize = 'none'
..textShadow = 'transparent'
..textShadow = 'none'
..overflow = 'hidden'
..transformOrigin = '0 0 0';
@@ -80,9 +85,6 @@ void _setStaticStyleAttributes(DomHTMLElement domElement) {
domElement.classList.add(transparentTextEditingClass);
}
// This property makes the input's blinking cursor transparent.
elementStyle.setProperty('caret-color', 'transparent');
if (_debugVisibleTextEditing) {
elementStyle
..color = 'purple'

View File

@@ -2528,6 +2528,36 @@ Future<void> testMain() async {
expect(textEditingDeltaState.composingExtent, -1);
});
});
group('text editing styles', () {
test('invisible element', () {
editingStrategy!.enable(
singlelineConfig,
onChange: trackEditingState,
onAction: trackInputAction,
);
final DomHTMLElement input = editingStrategy!.activeDomElement;
expect(input.style.color, 'transparent');
expect(input.style.background, 'transparent');
expect(input.style.backgroundColor, 'transparent');
expect(input.style.caretColor, 'transparent');
expect(input.style.outline, 'none');
expect(input.style.border, 'none');
expect(input.style.textShadow, 'none');
});
test('prevents effect of (forced-colors: active)', () {
editingStrategy!.enable(
singlelineConfig,
onChange: trackEditingState,
onAction: trackInputAction,
);
final DomHTMLElement input = editingStrategy!.activeDomElement;
expect(input.style.getPropertyValue('forced-color-adjust'), 'none');
});
});
}
DomKeyboardEvent dispatchKeyboardEvent(