Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 6db26bc

Browse files
authored
[web] ignore pointer events on plain text spans (#53694)
A semantic 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 the sized span to be chosen as the label representation. 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`. This PR removes pointer event handling from inert text spans. This fixes the click debounce logic. Fixes flutter/flutter#151265
1 parent 388547a commit 6db26bc

File tree

2 files changed

+32
-1
lines changed

2 files changed

+32
-1
lines changed

lib/web_ui/lib/src/engine/semantics/label_and_value.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,15 @@ final class SizedSpanRepresentation extends LabelRepresentationBehavior {
248248

249249
// The origin of the coordinate system is the top-left corner of the
250250
// parent element.
251-
..transformOrigin = '0 0 0';
251+
..transformOrigin = '0 0 0'
252+
253+
// The node may be tappable without having a more concrete role set on it,
254+
// such as "button". It will just have a tap handler. This could lead to
255+
// sized span to be chosen as the label representation strategy. However,
256+
// when pointer events land on the span the DOM `target` becomes the span
257+
// rather than the tappable element, and that breaks the debouncing logic
258+
// in `pointer_binding.dart`.
259+
..pointerEvents = 'none';
252260
semanticsObject.element.appendChild(_domText);
253261
}
254262

lib/web_ui/test/engine/semantics/semantics_text_test.dart

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,27 @@ Future<void> testMain() async {
285285

286286
semantics().semanticsEnabled = false;
287287
});
288+
289+
test('The <span> ignores pointer events', () async {
290+
semantics()
291+
..debugOverrideTimestampFunction(() => _testTime)
292+
..semanticsEnabled = true;
293+
294+
final SemanticsTester tester = SemanticsTester(owner());
295+
tester.updateNode(
296+
id: 0,
297+
label: 'Ignore pointer events',
298+
transform: Matrix4.identity().toFloat64(),
299+
rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
300+
);
301+
tester.apply();
302+
303+
expectSemanticsTree(owner(), '''
304+
<sem>
305+
<span style="pointer-events: none">Ignore pointer events</span>
306+
</sem>'''
307+
);
308+
309+
semantics().semanticsEnabled = false;
310+
});
288311
}

0 commit comments

Comments
 (0)