wrap focus() in a post update callback (flutter/engine#38958)

This commit is contained in:
nbayati
2023-01-17 16:54:47 -08:00
committed by GitHub
parent 73202c1da2
commit a2add485a1
2 changed files with 24 additions and 1 deletions

View File

@@ -61,7 +61,9 @@ class Tappable extends RoleManager {
// Request focus so that the AT shifts a11y focus to this node.
if (semanticsObject.isFlagsDirty && semanticsObject.hasFocus) {
element.focus();
semanticsObject.owner.addOneTimePostUpdateCallback(() {
element.focus();
});
}
}

View File

@@ -1628,6 +1628,27 @@ void _testTappable() {
semantics().semanticsEnabled = false;
});
test('focuses on tappable after element has been attached', () async {
semantics()
..debugOverrideTimestampFunction(() => _testTime)
..semanticsEnabled = true;
final SemanticsTester tester = SemanticsTester(semantics());
tester.updateNode(
id: 0,
hasTap: true,
hasEnabledState: true,
isEnabled: true,
isButton: true,
isFocused: true,
rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
);
tester.apply();
expect(flutterViewEmbedder.glassPaneShadow!.activeElement, tester.getSemanticsObject(0).element);
semantics().semanticsEnabled = false;
});
}
void _testImage() {