Skip to content

Commit cf12796

Browse files
Renzo-OlivaresRenzo Olivares
andauthored
Fix Semantics.identifier on TextField not working on web (flutter#170395)
Fixes flutter#155323 Before this change the `identifier` would not be updated even if marked dirty for a `SemanticRole` that had no `SemanticBehavior`s. After this change an `identifier` marked dirty is now updated even if the `SemanticRole` has no `SemanticBehavior`s. ## Pre-launch Checklist - [x] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [x] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [x] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [x] I signed the [CLA]. - [x] I listed at least one issue that this PR fixes in the description above. - [x] I updated/added relevant documentation (doc comments with `///`). - [x] I added new tests to check the change I am making, or this PR is [test-exempt]. - [x] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [x] All existing and new tests are passing. --------- Co-authored-by: Renzo Olivares <roliv@google.com>
1 parent a534b21 commit cf12796

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,10 @@ abstract class SemanticRole {
765765
}
766766

767767
final List<SemanticBehavior>? behaviors = _behaviors;
768-
if (behaviors == null) {
769-
return;
770-
}
771-
for (final SemanticBehavior behavior in behaviors) {
772-
behavior.update();
768+
if (behaviors != null) {
769+
for (final SemanticBehavior behavior in behaviors) {
770+
behavior.update();
771+
}
773772
}
774773

775774
if (semanticsObject.isIdentifierDirty) {

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

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,76 @@ void _testSemanticRole() {
204204
<sem id="flt-semantic-node-612" flt-semantics-identifier="test-id-333"></sem>
205205
</sem>''');
206206
});
207+
208+
test(
209+
'Sets id and flt-semantics-identifier on the element when SemanticRole has no behaviors',
210+
() {
211+
semantics()
212+
..debugOverrideTimestampFunction(() => _testTime)
213+
..semanticsEnabled = true;
214+
215+
final SemanticsTester tester = SemanticsTester(owner());
216+
tester.updateNode(
217+
id: 0,
218+
children: <SemanticsNodeUpdate>[
219+
tester.updateNode(
220+
id: 372,
221+
flags: const ui.SemanticsFlags(isTextField: true),
222+
), // SemanticTextField has no SemanticBehaviors.
223+
tester.updateNode(id: 599),
224+
],
225+
);
226+
tester.apply();
227+
228+
tester.expectSemantics('''
229+
<sem id="flt-semantic-node-0">
230+
<sem id="flt-semantic-node-372">
231+
<input />
232+
</sem>
233+
<sem id="flt-semantic-node-599"></sem>
234+
</sem>''');
235+
236+
tester.updateNode(
237+
id: 0,
238+
children: <SemanticsNodeUpdate>[
239+
tester.updateNode(
240+
id: 372,
241+
identifier: 'test-id-123',
242+
flags: const ui.SemanticsFlags(isTextField: true),
243+
),
244+
tester.updateNode(id: 599),
245+
],
246+
);
247+
tester.apply();
248+
249+
tester.expectSemantics('''
250+
<sem id="flt-semantic-node-0">
251+
<sem id="flt-semantic-node-372" flt-semantics-identifier="test-id-123">
252+
<input />
253+
</sem>
254+
<sem id="flt-semantic-node-599"></sem>
255+
</sem>''');
256+
257+
tester.updateNode(
258+
id: 0,
259+
children: <SemanticsNodeUpdate>[
260+
tester.updateNode(id: 372, flags: const ui.SemanticsFlags(isTextField: true)),
261+
tester.updateNode(id: 599, identifier: 'test-id-211'),
262+
tester.updateNode(id: 612, identifier: 'test-id-333'),
263+
],
264+
);
265+
tester.apply();
266+
267+
tester.expectSemantics('''
268+
<sem id="flt-semantic-node-0">
269+
<sem id="flt-semantic-node-372">
270+
<input />
271+
</sem>
272+
<sem id="flt-semantic-node-599" flt-semantics-identifier="test-id-211"></sem>
273+
<sem id="flt-semantic-node-612" flt-semantics-identifier="test-id-333"></sem>
274+
</sem>''');
275+
},
276+
);
207277
}
208278

209279
void _testRoleLifecycle() {

0 commit comments

Comments
 (0)