From a25e09a2665515b15786cf950706d6fbd7590ac3 Mon Sep 17 00:00:00 2001 From: Yegor Jbanov Date: Tue, 2 Jul 2024 11:37:06 -0700 Subject: [PATCH] [web] ignore pointer events on plain text spans --- .../src/engine/semantics/label_and_value.dart | 10 +++++++- .../engine/semantics/semantics_text_test.dart | 23 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/web_ui/lib/src/engine/semantics/label_and_value.dart b/lib/web_ui/lib/src/engine/semantics/label_and_value.dart index 9601074785b21..d5f543f660e80 100644 --- a/lib/web_ui/lib/src/engine/semantics/label_and_value.dart +++ b/lib/web_ui/lib/src/engine/semantics/label_and_value.dart @@ -248,7 +248,15 @@ final class SizedSpanRepresentation extends LabelRepresentationBehavior { // The origin of the coordinate system is the top-left corner of the // parent element. - ..transformOrigin = '0 0 0'; + ..transformOrigin = '0 0 0' + + // The node may be tappable without having a more concrete role set on it, + // such as "button". It will just have a tap handler. This could lead to + // sized span to be chosen as the label representation strategy. However, + // when pointer events land on the span the DOM `target` becomes the span + // rather than the tappable element, and that breaks the debouncing logic + // in `pointer_binding.dart`. + ..pointerEvents = 'none'; semanticsObject.element.appendChild(_domText); } diff --git a/lib/web_ui/test/engine/semantics/semantics_text_test.dart b/lib/web_ui/test/engine/semantics/semantics_text_test.dart index 6f9bc43f63b31..3a4e1f495aba2 100644 --- a/lib/web_ui/test/engine/semantics/semantics_text_test.dart +++ b/lib/web_ui/test/engine/semantics/semantics_text_test.dart @@ -285,4 +285,27 @@ Future testMain() async { semantics().semanticsEnabled = false; }); + + test('The ignores pointer events', () async { + semantics() + ..debugOverrideTimestampFunction(() => _testTime) + ..semanticsEnabled = true; + + final SemanticsTester tester = SemanticsTester(owner()); + tester.updateNode( + id: 0, + label: 'Ignore pointer events', + transform: Matrix4.identity().toFloat64(), + rect: const ui.Rect.fromLTRB(0, 0, 100, 50), + ); + tester.apply(); + + expectSemanticsTree(owner(), ''' + + Ignore pointer events + ''' + ); + + semantics().semanticsEnabled = false; + }); }