From 07584c64bb7ba8d9e79214c3667cdb16cfa67923 Mon Sep 17 00:00:00 2001 From: Yegor Date: Tue, 26 Apr 2022 13:26:00 -0700 Subject: [PATCH] [web] fix re-enabling tappable semantic elements (#32932) --- .../lib/src/engine/semantics/tappable.dart | 1 + .../test/engine/semantics/semantics_test.dart | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/lib/web_ui/lib/src/engine/semantics/tappable.dart b/lib/web_ui/lib/src/engine/semantics/tappable.dart index 99fd1c2761e95..77c2923fd2576 100644 --- a/lib/web_ui/lib/src/engine/semantics/tappable.dart +++ b/lib/web_ui/lib/src/engine/semantics/tappable.dart @@ -38,6 +38,7 @@ class Tappable extends RoleManager { semanticsObject.element.setAttribute('aria-disabled', 'true'); _stopListening(); } else { + semanticsObject.element.removeAttribute('aria-disabled'); // Excluding text fields because text fields have browser-specific logic // for recognizing taps and activating the keyboard. if (semanticsObject.hasAction(ui.SemanticsAction.tap) && diff --git a/lib/web_ui/test/engine/semantics/semantics_test.dart b/lib/web_ui/test/engine/semantics/semantics_test.dart index d7ec3fa45ae90..c848f48d53be5 100644 --- a/lib/web_ui/test/engine/semantics/semantics_test.dart +++ b/lib/web_ui/test/engine/semantics/semantics_test.dart @@ -1475,6 +1475,39 @@ void _testTappable() { semantics().semanticsEnabled = false; }); + + test('can switch tappable between enabled and disabled', () async { + semantics() + ..debugOverrideTimestampFunction(() => _testTime) + ..semanticsEnabled = true; + + void updateTappable({required bool enabled}) { + final SemanticsTester tester = SemanticsTester(semantics()); + tester.updateNode( + id: 0, + hasTap: true, + hasEnabledState: true, + isEnabled: enabled, + isButton: true, + rect: const ui.Rect.fromLTRB(0, 0, 100, 50), + ); + tester.apply(); + } + + updateTappable(enabled: false); + expectSemanticsTree(''); + + updateTappable(enabled: true); + expectSemanticsTree(''); + + updateTappable(enabled: false); + expectSemanticsTree(''); + + updateTappable(enabled: true); + expectSemanticsTree(''); + + semantics().semanticsEnabled = false; + }); } void _testImage() {