Skip to content

Commit

Permalink
[web] fix re-enabling tappable semantic elements (flutter#32932)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov authored Apr 26, 2022
1 parent 9467208 commit 07584c6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/web_ui/lib/src/engine/semantics/tappable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
33 changes: 33 additions & 0 deletions lib/web_ui/test/engine/semantics/semantics_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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('<sem role="button" aria-disabled="true" style="$rootSemanticStyle"></sem>');

updateTappable(enabled: true);
expectSemanticsTree('<sem role="button" style="$rootSemanticStyle"></sem>');

updateTappable(enabled: false);
expectSemanticsTree('<sem role="button" aria-disabled="true" style="$rootSemanticStyle"></sem>');

updateTappable(enabled: true);
expectSemanticsTree('<sem role="button" style="$rootSemanticStyle"></sem>');

semantics().semanticsEnabled = false;
});
}

void _testImage() {
Expand Down

0 comments on commit 07584c6

Please sign in to comment.