diff --git a/lib/web_ui/lib/src/engine/pointer_binding.dart b/lib/web_ui/lib/src/engine/pointer_binding.dart index 11502593eb97e..dd268a3774ffd 100644 --- a/lib/web_ui/lib/src/engine/pointer_binding.dart +++ b/lib/web_ui/lib/src/engine/pointer_binding.dart @@ -992,7 +992,7 @@ class _PointerAdapter extends _BaseAdapter with _WheelEventListenerMixin { _convertEventsToPointerData(data: pointerData, event: event, details: down); _callback(event, pointerData); - if (event.target == _viewTarget) { + if (event.target == _viewTarget && !EngineSemantics.instance.semanticsEnabled) { // Ensure smooth focus transitions between text fields within the Flutter view. // Without preventing the default and this delay, the engine may not have fully // rendered the next input element, leading to the focus incorrectly returning to diff --git a/lib/web_ui/lib/src/engine/semantics/text_field.dart b/lib/web_ui/lib/src/engine/semantics/text_field.dart index d1cf80852a61d..267d604599b37 100644 --- a/lib/web_ui/lib/src/engine/semantics/text_field.dart +++ b/lib/web_ui/lib/src/engine/semantics/text_field.dart @@ -114,16 +114,6 @@ class SemanticsTextEditingStrategy extends DefaultTextEditingStrategy { } subscriptions.clear(); lastEditingState = null; - - // If the text element still has focus, remove focus from the editable - // element to cause the on-screen keyboard, if any, to hide (e.g. on iOS, - // Android). - // Otherwise, the keyboard stays on screen even when the user navigates to - // a different screen (e.g. by hitting the "back" button). - // Keep this consistent with how DefaultTextEditingStrategy does it. As of - // right now, the only difference is that semantic text fields do not - // participate in form autofill. - DefaultTextEditingStrategy.scheduleFocusFlutterView(activeDomElement, activeDomElementView); domElement = null; activeTextField = null; _queuedStyle = null; diff --git a/lib/web_ui/test/engine/semantics/text_field_test.dart b/lib/web_ui/test/engine/semantics/text_field_test.dart index c93dc3bf4a86f..7792113fec29f 100644 --- a/lib/web_ui/test/engine/semantics/text_field_test.dart +++ b/lib/web_ui/test/engine/semantics/text_field_test.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:async'; import 'dart:typed_data'; import 'package:test/bootstrap/browser.dart'; @@ -159,7 +158,7 @@ void testMain() { // TODO(yjbanov): https://github.com/flutter/flutter/issues/46638 }, skip: ui_web.browser.browserEngine == ui_web.BrowserEngine.firefox); - test('Syncs semantic state from framework', () async { + test('Syncs semantic state from framework', () { expect( owner().semanticsHost.ownerDocument?.activeElement, domDocument.body); @@ -223,10 +222,12 @@ void testMain() { owner().semanticsHost.ownerDocument?.activeElement, textField.editableElement, ); - await Future.delayed(Duration.zero); + + // When semantics are enabled, deactivation shouldn't move focus or blur the + // editable element. Instead the engine/browser should move it accordingly. expect( owner().semanticsHost.ownerDocument?.activeElement, - EnginePlatformDispatcher.instance.implicitView!.dom.rootElement, + textField.editableElement, ); // There was no user interaction with the element, @@ -336,8 +337,7 @@ void testMain() { strategy.disable(); }); - test('Does not dispose and recreate dom elements in persistent mode', - () async { + test('Does not dispose and recreate dom elements in persistent mode', () { strategy.enable( singlelineConfig, onChange: (_, __) {}, @@ -362,12 +362,15 @@ void testMain() { // It doesn't remove the DOM element. final textField = textFieldSemantics.semanticRole! as SemanticTextField; expect(owner().semanticsHost.contains(textField.editableElement), isTrue); + // Editing element is not enabled. expect(strategy.isEnabled, isFalse); - await Future.delayed(Duration.zero); + + // When semantics are enabled, deactivation shouldn't move focus or blur the + // editable element. Instead the engine/browser should move it accordingly. expect( owner().semanticsHost.ownerDocument?.activeElement, - EnginePlatformDispatcher.instance.implicitView!.dom.rootElement, + textField.editableElement, ); });