[web] fix re-enabling tappable semantic elements (flutter/engine#32932)

This commit is contained in:
Yegor
2022-04-26 13:26:00 -07:00
committed by GitHub
parent 4658c2fa67
commit d6af36f7ce
2 changed files with 34 additions and 0 deletions

View File

@@ -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) &&

View File

@@ -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() {