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

Commit 0bf623b

Browse files
XilaiZhangnbayati
andauthored
wrap focus() in a post update callback (#38958) (#38980)
Co-authored-by: nbayati <99771966+nbayati@users.noreply.github.com>
1 parent 14194c4 commit 0bf623b

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,9 @@ class Tappable extends RoleManager {
6161

6262
// Request focus so that the AT shifts a11y focus to this node.
6363
if (semanticsObject.isFlagsDirty && semanticsObject.hasFocus) {
64-
element.focus();
64+
semanticsObject.owner.addOneTimePostUpdateCallback(() {
65+
element.focus();
66+
});
6567
}
6668
}
6769

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,27 @@ void _testTappable() {
16281628

16291629
semantics().semanticsEnabled = false;
16301630
});
1631+
1632+
test('focuses on tappable after element has been attached', () async {
1633+
semantics()
1634+
..debugOverrideTimestampFunction(() => _testTime)
1635+
..semanticsEnabled = true;
1636+
1637+
final SemanticsTester tester = SemanticsTester(semantics());
1638+
tester.updateNode(
1639+
id: 0,
1640+
hasTap: true,
1641+
hasEnabledState: true,
1642+
isEnabled: true,
1643+
isButton: true,
1644+
isFocused: true,
1645+
rect: const ui.Rect.fromLTRB(0, 0, 100, 50),
1646+
);
1647+
tester.apply();
1648+
1649+
expect(flutterViewEmbedder.glassPaneShadow!.activeElement, tester.getSemanticsObject(0).element);
1650+
semantics().semanticsEnabled = false;
1651+
});
16311652
}
16321653

16331654
void _testImage() {

0 commit comments

Comments
 (0)