mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
[web] - fix Safari textfield selection bug (flutter/engine#47917)
In order to fix Safari autofill, we've had to give inactive elements non-zero size because Safari does not respect offscreen or 0-sized inputs, and this leads to broken autofill behavior (see: https://github.com/flutter/engine/pull/43058). As part of these changes, we needed to disable pointer events for the parent `<form>` element so that we don't have pointer event collisions if users hover over or click into the invisible autofill elements within that form. This led to an issue where offsets weren't being calculated correctly for "active" inputs because they relied on pointer events bubbling up and being caught by the form. The fix is to explicitly set pointer events on the active inputs, so that we can correctly discern when our pointer event target is actually the input and correctly calculate the offsets. Fixes https://github.com/flutter/flutter/issues/136006
This commit is contained in:
parent
3295c04245
commit
5ae444a017
@ -321,6 +321,14 @@ class EngineAutofillForm {
|
||||
}
|
||||
|
||||
void placeForm(DomHTMLElement mainTextEditingElement) {
|
||||
// Since we're disabling pointer events on the form to fix Safari autofill,
|
||||
// we need to explicitly set pointer events on the active input element in
|
||||
// order to calculate the correct pointer event offsets.
|
||||
// See: https://github.com/flutter/flutter/issues/136006
|
||||
if(textEditing.strategy is SafariDesktopTextEditingStrategy) {
|
||||
mainTextEditingElement.style.pointerEvents = 'all';
|
||||
}
|
||||
|
||||
formElement.insertBefore(mainTextEditingElement, insertionReferenceNode);
|
||||
defaultTextEditingRoot.append(formElement);
|
||||
}
|
||||
|
||||
@ -2551,6 +2551,46 @@ Future<void> testMain() async {
|
||||
expect(autofillForm.formElement.style.pointerEvents, 'none');
|
||||
}, skip: !isSafari);
|
||||
|
||||
test(
|
||||
'the focused element within a form should explicitly set pointer events on Safari',
|
||||
() {
|
||||
final List<dynamic> fields = createFieldValues(<String>[
|
||||
'email',
|
||||
'username',
|
||||
'password',
|
||||
], <String>[
|
||||
'field1',
|
||||
'field2',
|
||||
'field3'
|
||||
]);
|
||||
final EngineAutofillForm autofillForm =
|
||||
EngineAutofillForm.fromFrameworkMessage(
|
||||
createAutofillInfo('email', 'field1'), fields)!;
|
||||
|
||||
final DomHTMLInputElement testInputElement = createDomHTMLInputElement();
|
||||
testInputElement.name = 'email';
|
||||
autofillForm.placeForm(testInputElement);
|
||||
|
||||
final List<DomHTMLInputElement> formChildNodes =
|
||||
autofillForm.formElement.childNodes.toList()
|
||||
as List<DomHTMLInputElement>;
|
||||
final DomHTMLInputElement email = formChildNodes[0];
|
||||
final DomHTMLInputElement username = formChildNodes[1];
|
||||
final DomHTMLInputElement password = formChildNodes[2];
|
||||
|
||||
expect(email.name, 'email');
|
||||
expect(username.name, 'username');
|
||||
expect(password.name, 'current-password');
|
||||
|
||||
// pointer events are none on the form and all non-focused elements
|
||||
expect(autofillForm.formElement.style.pointerEvents, 'none');
|
||||
expect(username.style.pointerEvents, 'none');
|
||||
expect(password.style.pointerEvents, 'none');
|
||||
|
||||
// pointer events are set to all on the activeDomElement
|
||||
expect(email.style.pointerEvents, 'all');
|
||||
}, skip: !isSafari);
|
||||
|
||||
tearDown(() {
|
||||
clearForms();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user