Skip to content

Commit 217aa3e

Browse files
authored
[web] - Fix broken TextField in semantics mode when it's a sibling of Navigator (#138446)
When a `TextField` is rendered before a `Navigator`, it breaks in semantics mode. This is because the framework generates the incorrect semantics tree (excludes the TextField) and when that tree gets sent to the engine, we don't get the signal to create the corresponding `<input>` element. This happens for a few reasons: * `ModalBarrier` uses `BlockSemantics` to drop the semantics of routes beneath the current route in `Navigator` * `ModalBarrier` mistakenly recognizes the widget outside of the `Navigator` to be its sibling * So we end up dropping the semantics node of the `TextField` rendered before it. The fix is to let `Navigator` generate a semantics node so that `ModalBarrier` doesn't mistakenly think widgets outside of `Navigator` are its siblings. `Navigator` doesn't currently do this, which causes all the nodes generated from its widget subtree to be directly attached to the parent semantics node above `Navigator` - since this is also the parent of `TextField`, it considers them siblings. Fixes flutter/flutter#129324
1 parent d437ee6 commit 217aa3e

23 files changed

Lines changed: 1276 additions & 1003 deletions

‎packages/flutter/test/cupertino/action_sheet_test.dart‎

Lines changed: 54 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -960,63 +960,81 @@ void main() {
960960
TestSemantics.root(
961961
children: <TestSemantics>[
962962
TestSemantics(
963+
id: 1,
964+
textDirection: TextDirection.ltr,
963965
children: <TestSemantics>[
964966
TestSemantics(
967+
id: 2,
965968
children: <TestSemantics>[
966969
TestSemantics(
967-
flags: <SemanticsFlag>[
968-
SemanticsFlag.scopesRoute,
969-
SemanticsFlag.namesRoute,
970-
],
971-
label: 'Alert',
970+
id: 6,
972971
children: <TestSemantics>[
973972
TestSemantics(
973+
id: 7,
974974
flags: <SemanticsFlag>[
975-
SemanticsFlag.hasImplicitScrolling,
976-
],
977-
children: <TestSemantics>[
978-
TestSemantics(
979-
label: 'The title',
980-
),
981-
TestSemantics(
982-
label: 'The message',
983-
),
984-
],
985-
),
986-
TestSemantics(
987-
flags: <SemanticsFlag>[
988-
SemanticsFlag.hasImplicitScrolling,
975+
SemanticsFlag.scopesRoute,
976+
SemanticsFlag.namesRoute
989977
],
978+
label: 'Alert',
979+
textDirection: TextDirection.ltr,
990980
children: <TestSemantics>[
991981
TestSemantics(
982+
id: 8,
992983
flags: <SemanticsFlag>[
993-
SemanticsFlag.isButton,
984+
SemanticsFlag.hasImplicitScrolling
994985
],
995-
actions: <SemanticsAction>[
996-
SemanticsAction.tap,
986+
children: <TestSemantics>[
987+
TestSemantics(
988+
id: 9,
989+
label: 'The title',
990+
textDirection: TextDirection.ltr,
991+
),
992+
TestSemantics(
993+
id: 10,
994+
label: 'The message',
995+
textDirection: TextDirection.ltr,
996+
),
997997
],
998-
label: 'One',
999998
),
1000999
TestSemantics(
1000+
id: 11,
10011001
flags: <SemanticsFlag>[
1002-
SemanticsFlag.isButton,
1002+
SemanticsFlag.hasImplicitScrolling
10031003
],
1004-
actions: <SemanticsAction>[
1005-
SemanticsAction.tap,
1004+
children: <TestSemantics>[
1005+
TestSemantics(
1006+
id: 12,
1007+
flags: <SemanticsFlag>[
1008+
SemanticsFlag.isButton
1009+
],
1010+
actions: <SemanticsAction>[
1011+
SemanticsAction.tap
1012+
],
1013+
label: 'One',
1014+
textDirection: TextDirection.ltr,
1015+
),
1016+
TestSemantics(
1017+
id: 13,
1018+
flags: <SemanticsFlag>[
1019+
SemanticsFlag.isButton
1020+
],
1021+
actions: <SemanticsAction>[
1022+
SemanticsAction.tap
1023+
],
1024+
label: 'Two',
1025+
textDirection: TextDirection.ltr,
1026+
),
10061027
],
1007-
label: 'Two',
1028+
),
1029+
TestSemantics(
1030+
id: 14,
1031+
flags: <SemanticsFlag>[SemanticsFlag.isButton],
1032+
actions: <SemanticsAction>[SemanticsAction.tap],
1033+
label: 'Cancel',
1034+
textDirection: TextDirection.ltr,
10081035
),
10091036
],
10101037
),
1011-
TestSemantics(
1012-
flags: <SemanticsFlag>[
1013-
SemanticsFlag.isButton,
1014-
],
1015-
actions: <SemanticsAction>[
1016-
SemanticsAction.tap,
1017-
],
1018-
label: 'Cancel',
1019-
),
10201038
],
10211039
),
10221040
],

‎packages/flutter/test/cupertino/date_picker_test.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1824,7 +1824,7 @@ void main() {
18241824
),
18251825
);
18261826

1827-
tester.binding.pipelineOwner.semanticsOwner!.performAction(4, SemanticsAction.decrease);
1827+
tester.binding.pipelineOwner.semanticsOwner!.performAction(5, SemanticsAction.decrease);
18281828
await tester.pumpAndSettle();
18291829

18301830
expect(date, DateTime(2018, 6, 7));

‎packages/flutter/test/cupertino/dialog_test.dart‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -201,33 +201,37 @@ void main() {
201201
TestSemantics(
202202
children: <TestSemantics>[
203203
TestSemantics(
204-
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
205204
children: <TestSemantics>[
206205
TestSemantics(
207-
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute, SemanticsFlag.namesRoute],
208-
label: 'Alert',
206+
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
209207
children: <TestSemantics>[
210208
TestSemantics(
211-
flags: <SemanticsFlag>[
212-
SemanticsFlag.hasImplicitScrolling,
213-
],
214-
children: <TestSemantics>[
215-
TestSemantics(label: 'The Title'),
216-
TestSemantics(label: 'Content'),
217-
],
218-
),
219-
TestSemantics(
220-
flags: <SemanticsFlag>[
221-
SemanticsFlag.hasImplicitScrolling,
222-
],
209+
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute, SemanticsFlag.namesRoute],
210+
label: 'Alert',
223211
children: <TestSemantics>[
224212
TestSemantics(
225-
flags: <SemanticsFlag>[SemanticsFlag.isButton],
226-
label: 'Cancel',
213+
flags: <SemanticsFlag>[
214+
SemanticsFlag.hasImplicitScrolling,
215+
],
216+
children: <TestSemantics>[
217+
TestSemantics(label: 'The Title'),
218+
TestSemantics(label: 'Content'),
219+
],
227220
),
228221
TestSemantics(
229-
flags: <SemanticsFlag>[SemanticsFlag.isButton],
230-
label: 'OK',
222+
flags: <SemanticsFlag>[
223+
SemanticsFlag.hasImplicitScrolling,
224+
],
225+
children: <TestSemantics>[
226+
TestSemantics(
227+
flags: <SemanticsFlag>[SemanticsFlag.isButton],
228+
label: 'Cancel',
229+
),
230+
TestSemantics(
231+
flags: <SemanticsFlag>[SemanticsFlag.isButton],
232+
label: 'OK',
233+
),
234+
],
231235
),
232236
],
233237
),

‎packages/flutter/test/cupertino/text_field_test.dart‎

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,20 @@ void main() {
525525
children: <TestSemantics>[
526526
TestSemantics(
527527
id: 3,
528-
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
529528
children: <TestSemantics>[
530529
TestSemantics(
531530
id: 4,
532-
flags: <SemanticsFlag>[SemanticsFlag.isTextField,
533-
SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled,],
534-
actions: <SemanticsAction>[SemanticsAction.tap,
535-
SemanticsAction.didGainAccessibilityFocus,],
536-
textDirection: TextDirection.ltr,
531+
flags: <SemanticsFlag>[SemanticsFlag.scopesRoute],
532+
children: <TestSemantics>[
533+
TestSemantics(
534+
id: 5,
535+
flags: <SemanticsFlag>[SemanticsFlag.isTextField,
536+
SemanticsFlag.hasEnabledState, SemanticsFlag.isEnabled,],
537+
actions: <SemanticsAction>[SemanticsAction.tap,
538+
SemanticsAction.didGainAccessibilityFocus,],
539+
textDirection: TextDirection.ltr,
540+
),
541+
],
537542
),
538543
],
539544
),
@@ -548,7 +553,7 @@ void main() {
548553
));
549554

550555
expect(focusNode.hasFocus, isFalse);
551-
semanticsOwner.performAction(4, SemanticsAction.didGainAccessibilityFocus);
556+
semanticsOwner.performAction(5, SemanticsAction.didGainAccessibilityFocus);
552557
await tester.pumpAndSettle();
553558
expect(focusNode.hasFocus, isTrue);
554559
semantics.dispose();

0 commit comments

Comments
 (0)